Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a GUI timer that does not reset when a new player joins?

Asked by 5 years ago
Edited 5 years ago

I made a GUI timer that works, but when someone rejoins or joins the game, the timer for that person resets while for others the timer remains as it is.

How do I make a timer that displays what value it is on when a new player joins instead of reseting back to 60 for that person?

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

I would use a NumberValue in ReplicatedStorage that acts as the timer. For every second that passes, you can change its Value from a server script, and listen to the .Changed of the value from the local scripts to update the gui. This way, when a player joins, their script will pick up the change and update their gui to be synced with the others.

For example, if there was a NumberValue called Timer in ReplicatedStorage, you could do this in a server script:

local Timer = 1
while true do
    game.ReplicatedStorage.Timer.Value = Timer
    Timer = Timer + 1
    wait(1)
end 

And in a LocalScript inside the gui:

game.ReplicatedStorage.Timer.Changed:Connect(function(NewVal)
    script.Parent.Text = "time passed: " .. NewVal
end)

Which should keep all clients up-to-date, regardless of when they join.

0
Thanks! It does not let me to accept your answer for some odd reason.. Thesquid13 301 — 5y
0
nvm Thesquid13 301 — 5y
Ad

Answer this question