【问题标题】:(Also roblox related)Countdown freezes at a random number(也与roblox相关)倒计时冻结在一个随机数
【发布时间】:2020-12-17 13:35:59
【问题描述】:

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

脚本确定将有多少秒,然后将其触发到所有玩家客户端,并且本地脚本将文本更改为秒。但是当我测试游戏时,countdow 会冻结在一个数字或一个随机数上,这又是脚本:

脚本:

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)

【问题讨论】:

  • 它是否始终冻结在同一个数字上?
  • 它可以冻结在一个数字上。

标签: roblox


【解决方案1】:

每次服务器触发事件​​时,您的 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

【讨论】:

  • 嘿,@GameBuilderLol,我很高兴听到这个消息!您能否将此标记为已接受的答案。
  • 哈哈哈哦不,那么看来你的问题出在其他地方。也许这不是答案。
  • 实际上我需要这个答案,我说的是倒计时冻结在一个数字上,冻结的显着数字是 22、20、19、18 和 12。(我将 secondsRemaining 更改为 35) .
  • 所以在倒计时的时候,一切都很好。但是倒计时会在这里和那里冻结一些数字,但仍会继续?还是倒计时冻结而不再继续?
  • 它会冻结但最终会继续运行
猜你喜欢
  • 2012-10-23
  • 2020-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-14
  • 1970-01-01
  • 1970-01-01
  • 2021-03-22
相关资源
最近更新 更多