What i am trying to make is a game where a random player gets teleported to an obstacle course. If the player falls in the water (touches a part called "Water") he will fail. If he makes it (touches a part called "Clear1" the player will have to do the 2nd obstacle course. So far everything works!
Now i also want the player to complete the course within a time limit! So i scripted a timer. This also works fine! So far i didnt script what will happen when the time runs out. So i made that.
Now when the round starts everything seems to be working fine but once the timer reaches 0 the player will be teleported to the lobby once every second even if the timer isnt at 0 anymore!
Here is the script:
for i = StageOne, 0, -1 do -- The variable "StageOne" has the value 80
local SpawnLobby = game.Workspace.SpawnLobby
for _,p in pairs(game.Players:GetPlayers()) do
ChangeText("Time left: " ..i) --ChangeText is an above made function that changes the text propertie of a TextLabel
wait(1)
choosen.Character["Right Leg"].Touched:Connect(function(leg) -- the variable "choosen" is a random choosen player.
if leg.Name == "Water" then
ChangeText(choosen.Name.. " fall into the water!")
choosen.Character.Torso.CFrame = CFrame.new(SpawnLobby.Position)
elseif leg.Name == "Clear1" then
game.win1.Value = true --win1 is a bool value
ChangeText(choosen.Name.. " has cleared Stage 1! Well done!")
choosen.Character.Torso.CFrame = CFrame.new(SpawnLobby.Position)
choosen.leaderstats.Coins.Value = choosen.leaderstats.Coins.Value + 20
choosen.leaderstats["Stage 1"].Value = choosen.leaderstats["Stage 1"].Value + 1
--if i remove the below part everything works fine
elseif i == 0 then
ChangeText(choosen.Name.. " ran out of time!")
choosen.Character.Torso.CFrame = CFrame.new(SpawnLobby.Position)
else
end
end)
end
end
I spend hours trying to solve this problem but at this point i really dont know what to do anymore. Any help is appreciated. Thanks.
