所以我正在开发一款游戏。我提供的代码工作正常,但由于某种原因,当我死后,计时器从头开始重置。我不知道是什么导致了这个问题。
local countdownLabel = script.Parent
local intermissionUI = script.Parent.Parent.Parent
local function countdown()
local counter = 20
while counter > 0 do
countdownLabel.Text = tostring(counter)
counter = counter - 1
wait(1)
end
end
local function peaceDown()
local counter = 30
while counter > 0 do
countdownLabel.Text = tostring(counter)
counter = counter - 1
wait(1)
end
end
local function mainCountdown()
local counter = 270
while counter > 0 do
countdownLabel.Text = tostring(counter)
counter = counter - 1
wait(1)
end
end
local function hideUI()
intermissionUI.ImageLabel.Visible = false
wait(10)
intermissionUI.ImageLabel.Visible = true
end
while true do
countdown()
peaceDown()
mainCountdown()
hideUI()
end
以下是 startergui 文档中的一些信息:
当 Player.Character 重生时,其 PlayerGui 的内容是 清空了。然后,StarterGui 的子级连同它们的子级一起被复制 后代进入 PlayerGui。
因此,每次你死亡时,都会生成一个新脚本来替换之前的脚本。如果这个脚本应该为每个玩家运行,您可以创建一个脚本,使用 Players.PlayerAdded 将脚本添加到他们的玩家文件夹中。
如果您计划进行一次全局倒计时,则可以在serverstorage中使用一个脚本来更新复制存储中的全局变量,然后由更新标签的本地脚本访问该变量