Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making a timer in a game using FE?

Hey guys!

So I'm attempting to make a timer for a round-based game of mine, but I'm having a little trouble choosing a method;

  • Should I handle the loop in the client? If so, how might I go about doing this?
  • Or should I just allow the server to do the job, sending them the time left every time it changes, and just reflect that in the GUI?

Thanks a ton! Saenae

1 answer

✓ Accepted answer

You should do as little as possible in the client besides display the value.

--script
local timer = game.ReplicatedStorage:WaitForChild('IntValue')
timer.Value = 300
while wait(1) do
    timer.Value = timer.Value - 1
end

--localscript
local timer = game.ReplicatedStorage:WaitForChild('IntValue')
local label = --path to gui
timer.Changed:connect(function(val)
    label.Text = val
end)

9 comments

0

Where is your remote event he is going to want a script

0

If you're using .Changed, you don't need a remote event.

2

It is not a good idea to do this as you rely on the network speed ect to replicate this change which may take more than one second and will be inconsistent due to the change not being done instantaneously for all clients.

1

Also you should do as much as possible (that is safe to do) on the client side.

0

Wrong. One, network speed issues are the players' problem, not the scripter's. And if you are implying to do the timer loop on the client, that's guaranteeing even moreso an inconsistency, as you can't synchornize the loops. .Changed events are synchronized. Three, no, you don't do anything on the client unless it is gui or input work. Do not encourage new scripters to give power to the client (th

0

e opposite of filtering enabled philosophy). Thank you.

0

I would use a RemoteEvent for this, but yeah, the loop should be done on the server to keep everything consistent.

0

Thanks for your answer Cabbler! :D

0

Np. It is only the standard model for replication. Ignore people like kingdom5 who don't quite understand filtering/networking.

This discussion is preserved as it was. New answers, comments, and votes are closed.