My timer is not the same for two people

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)

Can you provide us with the script? There’s not much to go on here.

1 Like

The script itself functions fine, but I just need help adding a part where the text on every player in the server is the same.

Sounds like you’re not firing all clients from the server script.
Can’t do much without a script though

Like I said, My script functions fine, I just need to add code so that the text on each player in the server is the same.

Yeah, that’s the code. :FireAllClients()

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. :slight_smile:

2 Likes

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.

FYI: (I’ll put this above too) My code for timer is a local script and its parent is a TextLabel.

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".

So let me guess, I put the server script in serverscriptservice, and the local script into the timer script correct?

Sounds like you’re having trouble with relativity

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

1 Like

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.

You have probably forgotten to close a function on one of your scripts

Hmm I don’t think so… Anyway here 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 are meant to close the while loop so you should add an end, do this: