gui = game.StarterGui.raidgui.raidtimer.raidtime timevalue = script.Parent.TimeValue maxtime = script.Parent.TimeValue.Value for i = 1, timevalue.Value do wait(1) gui.Text = tostring(maxtime-timevalue.Value) timevalue.Value = timevalue.Value - 1 end
I am using this code to make a timer and it worked when I pressed run but when I entered a game, it seemed like as soon as the server started, the timer started, but when a player enters, the timer stops. What can I do to change this?
Info: I am using StarterGui-ScreenGui-Frame for the Gui the TimeValue is in Workspace along with the script.
Everything in StarterGui is cloned into a player's PlayerGui when they enter the game and each time they respawn. Therefore the timer will only change when a player dies.
The way I recommend doing a countdown GUI is to use two scripts. The first script is inside an IntValue in Workspace, and it makes that value count down. Name the value something that nothing else will be named, for this example I'll assume it's named 'count'. The second script is in the GUI. The second script sets the the text of the GUI to the number of the value in Workspace.
Script in the IntValue:
local time = 50 for i = time,0,-1 do wait(1) script.Parent.Value = i end
In case you don't know: for loops have a third, optional argument that determines how much is added to 'i' each time the loop iterates. If we set it to -1, it will effectively count down.
Script in the GUI:
local label = script.Parent local count = Workspace:WaitForChild("count") count.Changed:connect(function() label.Text = tostring(count.Value) end)
Hope I helped!