Im making a for loop and it does not loop like I want it to.
function newRound(plr) --Main function :) if serverStarted ~= nil then for i=1, 10,1 do wait(1) updateGui("New round starting in "..timeToWait-1) end end end
No outputs
FULL SCRIPT:
--//VALUES\\-- local maps = {"Map1","Map2","Map3","Map4","Map5","Map6"} mapChosen = "" roundTime = 1*60 -- 1 minute timeToWait = 10 serverStarted = false --//CODE\\-- function newRound(plr) --Main function :) if serverStarted ~= nil then for i=1, 10, 1 do wait(1) updateGui("New round starting in "..timeToWait-1) end mapChosen = maps[math.random(#maps)] changeMap(mapChosen) updateGui("Map chosen is "..mapChosen) wait(3) tpPlayers("map") updateGui("Round end in 10 seconds") --should be minutes but too long and its late now lmao wait(10) tpPlayers("lobby") updateGui("Round is over!") removeMap() wait(1) newRound(plr) end end function changeMap(map) --Change the map if workspace:FindFirstChild(mapChosen) then removeMap() else local map = game.ReplicatedStorage.Maps:FindFirstChild(mapChosen):Clone() map.Parent = workspace wait() end end function updateGui(msg) --Update the message for i,v in pairs(game.Players:GetPlayers()) do v.PlayerGui:WaitForChild("Gui") --Wait for the GUI v.PlayerGui.Gui.Text.Text = msg wait() end end function removeMap() --Remove the map if workspace:FindFirstChild(mapChosen) then workspace:FindFirstChild(mapChosen):Destroy() wait() end end function tpPlayers(location) --Teleport players to map for i,v in pairs(game.Players:GetPlayers()) do local chr = v.Character if chr then if location == "map" then chr:MoveTo(Vector3.new(0,0,0)) elseif location == "lobby" then chr:MoveTo(workspace.Lobby.Position) end else print(v.Name.."'s character not found.") --Error message end end end game.Players.PlayerAdded:connect(function(plr) serverStarted = true newRound(plr) end)
The problem with your code:
It is continually changing the timeToWait value to 9. So:
local done = false for i = timeToWait,1,-1 do wait(1) updateGui(""..i) if i == 1 then done == true end end repeat wait() until done == true -- for loops do not stop the code like while loops