(也与roblox相关)倒计时冻结在一个随机数

(Also roblox related)Countdown freezes at a random number

所以有 2 个脚本:script 和 localscript。

脚本确定会有多少秒,然后将其触发给所有玩家客户端,本地脚本将文本更改为秒。但是当我测试游戏时,倒计时要么冻结在一个数字上,要么冻结在一个随机数字上,无论如何这里又是脚本:

脚本:

local ReplicatedStorage = game:GetService("ReplicatedStorage")


local remoteEvent = ReplicatedStorage:WaitForChild("IntermissonEvent")

local secondsRemaining = 15

for t = secondsRemaining, 0, -1 do
    remoteEvent:FireAllClients(t)
    wait(1)
end

本地文字:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("IntermissonEvent")

local function onTimerUpdate(seconds)
    script.Parent.Text =(seconds)
    wait(15)
    script.Parent.Parent.CountdownText.Visible = false
    script.Parent.Parent.IntermissionText.Visible = false
    script.Parent.Parent.TextLabel.Text ="Vote for a Map!"
    script.Parent.Parent.MapVotingFrame.Visible = true
    end

remoteEvent.OnClientEvent:Connect(onTimerUpdate)

每次服务器触发事件​​时,您的 LocalScript 都是 运行 所有这些逻辑。不要等待,而是使用 if-then.

检查值
local function onTimerUpdate(seconds)
    script.Parent.Text = tostring(seconds)

    if seconds == 0 then
        script.Parent.Parent.CountdownText.Visible = false
        script.Parent.Parent.IntermissionText.Visible = false
        script.Parent.Parent.TextLabel.Text = "Vote for a Map!"
        script.Parent.Parent.MapVotingFrame.Visible = true
    end
end