You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Roblox悬浮文本倒计时异常:无法触发Floor_1显示求助

问题分析与修复方案

核心问题点

  • 第17行判断逻辑错误:CountDownNumber.Text是字符串属性,没有.Value字段;且倒计时结束后Text的值是字符串"0",不是数字0,原判断条件完全不成立。
  • 冗余轮询循环:for循环结束后倒计时已经走到0,没必要用while task.wait(0.3)重复判断,直接设置目标文本即可。
  • attribute逻辑混乱:第14行在循环内反复把attribute.Value设为false,会导致倒计时过程中玩家再次触碰就会重复触发,应该把这行移到整个倒计时结束后。

修复后的代码

CountDownNumber = game.Workspace.Host["Floating Text"].LABEL
script.Parent.Touched:Connect(function(HIT)
    local player = HIT.Parent:FindFirstChild("Humanoid")
    local attribute = game.StarterPlayer.StarterCharacterScripts.number
    if not player then return end
    if attribute.Value == false then
        attribute.Value = true 
        CountDownNumber.Text = "30"
        for count= 29, 0, -1 do
            CountDownNumber.Text = tostring(count)
            task.wait(1)
        end
        -- 倒计时结束直接切换文本
        CountDownNumber.Text = "Floor_1"
        attribute.Value = false
    end
end)

额外优化说明

  • 用tostring(count)直接赋值文本,避免字符串转数字时可能出现的异常,比原代码的CountDownNumber.Text -1更可靠
  • 移除了未使用的players变量,精简代码结构
  • 调整attribute.Value = false的位置,确保整个倒计时过程不会被重复触发

内容的提问来源于stack exchange,提问作者candy craving crab

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 04:54:54