Ok so what I mean by this is when two or more people join my game, the timer GUI is different for each person because they joined at different times. So sometimes, a player is in the map, while another players is in intermission. Also, my timer code is a local script that is a parent of a TextLabel. Don’t get what I mean? Ask me questions. Thanks and have a great day! Here is my script now:
while true do
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(currenttime)
game.Workspace.Sound1:Play()
script.Parent.Text = "Welcome! A new map will be chosen in".. tostring(currenttime)
end)
You’re most likely handling this timer from the client, I would assume. You can use a RemoteEvent to mitigate this. You can simply just handle most of the counting down from the server, and use the event to tell all of the clients to update their times. I’ll show an example below.
-- On the server
for i = 10, 1, -1 do -- this will count from 10 to 1 with -1 as the step.
game.ReplicatedStorage.RemoteEvent:FireAllClients(i) -- Tell the client the current time
wait(1)
end
-- On the Client
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(currenttime)
print("Time is: " .. tostring(currenttime))
end)
Of course this is just a quick example of how you can use RemoteEvents in your use-case and isn’t extremely practical for large-scale use. You can also use something like an IntegerValue and update it on the server if you don’t want to use a remote event, or even just tell the client when to start, stop, and reset the timer.
I hope this helped! Let me know if you’re confused on something.
for the server part and the client part, do they go in different script? If so, were do i put them and what kind of script? (Sorry Im a beginner. I’m also kinds confused on how this works)
Yep. Server scripts run on the server (meaning they run on Roblox’s servers) so you’ll have to make a normal script and put it in a place like ServerScriptService or Workspace. Client scripts (or LocalScripts) run code on your computer, and changes made in a LocalScript are only visible to you unless they’re somehow replicated to the server and broadcasted to everybody else in-game. Like I said above, this replication can be achieved with a RemoteEvent.
Unfortunately, I can’t write all of your code for you, so you’ll have to take the information I gave in and use it to implement your timer yourself. If your question is about how you can set the timer text from a script, you can do script.Parent.Text = "Text here".
You just make one clock on the server, and fire it via remote event like many have already suggested. Yes the script goes in ServerScriptService since it’s a server script (it’s not the only place for server scripts but it’s easy to organize your game with scripts in one spot). And to add on it might be beneficial for you to read up on how RemoteEvents work (that’s a tutorial style article vs. the API documentation that’s hard to follow), also @Alvin_Blox has a great video tutorial explaining it.
@crywink basically answered this question but hopefully the extra resources are helpful for anyone observing this thread. I’m a physicist - I saw the title and I had to respond to this thread lol
For some reason, when I try the thing you suggested, it gives an error. ( Expected ‘)’ (to close '('at line 2) got ‘end’.) Line two is game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(currenttime)
and i put end) at the bottom. What is wrong? Before that there weren’t any errors in script analysis or output.
'''
while true do
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(currenttime)
game.Workspace.Sound1:Play()
script.Parent.Text = "Welcome! A new map will be chosen in".. tostring(currenttime)
end)
'''