hey, i have a problem with the countdown gui, namely the time that should count down is counted differently for each player.
Time counts down correctly when there is only 1 player on the server.
Example:
Time works properly when Player1 is alone on the server, when Player2 joins then the countdown starts to break.
when Player1 has 5 seconds left, Player2 has 10 seconds left. Additionally, the time is subtracted twice when there are more players on the server.
I have tried several ways to solve this problem, but nothing has helped.
even tried putting a script in ServerScriptService and copying Gui from ReplicatedStorage to PlayerGui player.
This is a script:
local ServerTime = game.ReplicatedStorage.ServerTime.Value -- NumberValue
ServerTime = 40 -- Starter Time
while true do
repeat
wait(1)
ServerTime = ServerTime - 1
script.Parent.TextLabel.Text = ServerTime
until script.Parent.TextLabel.Text == "0"
if script.Parent.TextLabel.Text == "0" then
game.ReplicatedStorage.Part:Clone().Parent = game.Workspace
ServerTime = 40
end
end
local servertime = game.ReplicatedStorage.ServerTime
while task.wait(1) do
if servertime.Value == 0 then
servertime.Value = 40
game.ReplicatedStorage.Part:Clone().Parent = Workspace
end
servertime.Value -= 1
end
this is the local script
local servertime = game.ReplicatedStorage.ServerTime
servertime.Changed:Connect(function(val)
script.Parent.TextLabel.Text = val
end)
script.Parent.TextLabel.Text = servertime.Value
sorry if there is any spelling mistakes
edit: Added the part cloning to the script
By the way I am using an IntValue.
You are changing the time value locally only (you are only changing it for the player itself, the other players can’t see those changes which is why the time is out of sync for the players).
Instead:
Update the time value in a ServerScript in ServerScriptService.
On the client, listen to those changes in a LocalScript and update the text accordingly on the text label.
You can achieve this with the code provided above.
local Workspace = workspace
local function CountDown(Timer)
local Hint = Instance.new("Hint")
Hint.Parent = Workspace
for Number = Timer, 0, -1 do
Hint.Text = Number
task.wait(1)
end
Hint:Destroy()
end