this script I made is supposed to change the ''StageLabel'' Text Label to whatever stage the player is in , if the player dies (for example in stage two) the label goes back to'' Stage One'' instead of ''Stage Two'' and its not supposed to happen, how do i fix this? (there is also a timer, but the timer works as intended)
''local StageGui = script.Parent
local StageLabel = StageGui.StageLabel
local TimerLabel = StageGui.TimerLabel
local InStage = false
local Player = game.Players.LocalPlayer
wait(2)
local stages = {
game.Workspace.StageOne,
game.Workspace.StageTwo,
game.Workspace.StageThree
}
local function StartTimer()
local minutes = 0
local seconds = 0
repeat
seconds = seconds + 1
if seconds == 60 then
minutes = minutes + 1
seconds = 0
end
if minutes > 9 and seconds > 9 then
TimerLabel.Text = minutes .. ":" .. seconds
elseif minutes > 9 then
TimerLabel.Text = minutes .. ":0" .. seconds
elseif seconds > 9 then
TimerLabel.Text = "0".. minutes .. ":" .. seconds
else
TimerLabel.Text = "0".. minutes .. ":0" .. seconds
end
wait(1)
until not InStage
end
local function EndTimer()
InStage = false
TimerLabel.Text = "00:00"
end
for i, stage in pairs(stages) do
stage.Start.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
StageLabel.Text = stage.Start.StageName.Value
InStage = true
StartTimer()
end
end)
end
for i, stage in pairs(stages) do
stage.End.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
EndTimer()
InStage = false
end
end)
end