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

Making a timer in a game using FE?

Asked by
saenae 318 Moderation Voter
7 years ago

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

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago

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)
0
Where is your remote event he is going to want a script johndeer2233 439 — 7y
0
If you're using .Changed, you don't need a remote event. cabbler 1942 — 7y
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. User#5423 17 — 7y
1
Also you should do as much as possible (that is safe to do) on the client side. User#5423 17 — 7y
View all comments (5 more)
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 cabbler 1942 — 7y
0
e opposite of filtering enabled philosophy). Thank you. cabbler 1942 — 7y
0
I would use a RemoteEvent for this, but yeah, the loop should be done on the server to keep everything consistent. Perci1 4988 — 7y
0
Thanks for your answer Cabbler! :D saenae 318 — 7y
0
Np. It is only the standard model for replication. Ignore people like kingdom5 who don't quite understand filtering/networking. cabbler 1942 — 7y
Ad

Answer this question