My script is
while wait() do if Players.Value >= 2 then for i = 15, 1, -1 do StatusBar.Text = "Round begins in " .. i wait(1) end for i = 240, 1, -1 do Timer.Text = "Time: " .. i wait(1) end elseif Players.Value < 2 then StatusBar.Text = "There needs to be more than 1 player to begin the round." end end
Any suggestion on how to make the countdown actually work?
In workspace, make a script that has "StringValue" module and change the module name to serverTimer
game.Workspace.Script.serverTimer
This is the code you need for the script:
timer = script.serverTimer local seconds = 100 -- Change the seconds to what ever you like repeat timer.Value = "There are " .. seconds .. " seconds left" wait(1) seconds = seconds - 1 until seconds == -1 -- It will keep decreasing until it reaches -1
In StarterGui, make a ScreenGui that has a TextLabel inside it. Inside the TextLabel, add a local script
game.StarterGui.ScreenGui.TextLabel.LocalScript
This is the code for the local script:
game.Workspace.serverScript.serverTimer.Changed:Connect(function() script.Parent.Text = game.Workspace.serverScript.serverTimer.Value end)
This works without causing any issues on the server side and the client side because the "StringValue" module is the middle man. Basically the server script changes the value of the "StringValue" module and the local script updates the player's text every time the module is changed. Let me know if you have any questions
EDIT:
You can make changes to the server script and by changing the code into a function:
function createAnouncer(message, timer) if (timer == 0) then script.ServerTimer.Value = message wait(4) return 0 end repeat local sec = " seconds" if (timer == 1) then sec = " second" end script.ServerTimer.Value = message .. timer .. sec wait(1) timer = timer - 1 until timer <= -1 end -- This can help save tons of time and lines of code when you want to change the status of the game createAnouncer("Intermission for ", 20) createAnouncer("Choosing map...", 0) createAnouncer("Choosing monster...", 0) createAnouncer("Starting game...", 0) createAnouncer("Survive for ", 150) createAnouncer("Time has ended! ", 0)