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

global countdown timer help please?

Asked by
rokedev 71
6 years ago
Edited 6 years ago

so ive been trying to make a global countdown timer that is in sync with all players, and i dont know why but it just doesnt work

-- server script
local event = Instance.new("RemoteEvent")
event.Parent = game.Workspace
event.Name = "UpdateText"
game.Workspace.UpdateText:FireAllClients()

-- local script
local client = game.Players.LocalPlayer
local playergui = client.PlayerGui
local event = game.Workspace:FindFirstChild("UpdateText")
event.OnClientEvent:connect(function()
for i=850,0,-1 do 
    wait(1)
    playergui.ScreenGui.Frame.TextLabel.Text = ("Time left: "..i)
end
end)

1 answer

Log in to vote
1
Answered by
yyyyyy09 246 Moderation Voter
6 years ago

I would send the timer on the server rather than the client

Server

local event = game:GetService("ReplicatedStorage"):FindFirstChild("UpdateText")
-- I would put the event in ReplicatedStorage so it's filtering enabled
local timeLength = 850

for i=timeLength,0,-1 do
    wait(1)
    event:FireAllClients(i)
end


Client

local event = game:GetService("ReplicatedStorage"):FindFirstChild("UpdateText")
-- I would put the event in ReplicatedStorage so it's filtering enabled
local  client = game.Players.Localplayer
local playergui = client.PlayerGui


event.OnClientEvent:Connect(function(time)
    playergui.ScreenGui.Frame.TextLabel.Text = ("Time left: " .. time)
end)


This should keep all clients in sync with each other by firing all the clients at the same time

Ad

Answer this question