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

How to make a timer that runs server side and affects clients?

Asked by 6 years ago

I have not been able to figure out how to run a timer server side and then transfer the time to the client side so that when they die, the time keeps running and doesn’t get reset. I’ve tried remote functions and events. Any suggestions?

0
have you really tried GingeyLol 338 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

There's a few ways you could do this

Option 1: Have an int value the server updates to count down, which is accessible by the client so long as it's somewhere it can access like workspace.

-------------------------

Option 2: Use a remote function to return the time left when the client requests it;

Server script:

local timeLeft = 100

spawn(function()
    for i = 100, 1, -1 do
        wait(1)
        timeLeft = i
    end
end)

function GetTime()
    return timeLeft
end

script.RemoteFunction.OnServerInvoke = GetTime

Local script:

while wait(1) do
    print(workspace.GetTime.RemoteFunction:InvokeServer())
end

-------------------------

Option 3: Have the server send the time to all the clients every 1 second;

Server script:

local timeLeft = 100

spawn(function()
    for i = 100, 1, -1 do
        wait(1)
        timeLeft = i

        script.RemoteEvent:FireAllClients(timeLeft)
    end
end)

Local script:

workspace.GetTime.RemoteEvent.OnClientEvent:Connect(function(timeLeft)
    print(timeLeft)
end)
Ad

Answer this question