I’m trying to make my top bar function right, but the timer only visibly counts down live on the server’s screen, how do I fix this? It still counts down like it’s supposed to on server, but on client, you have to reset to see the timer countdown
local StatusBar = game.StarterGui.TopFrame.Bar
local GameStatus = "Intermission"
local Time = 31
function GetPlayerCount()
Players = #game.Players:GetPlayers()
end
wait(1)
while true do
if GameStatus == "InGame" then
GetPlayerCount()
if Players == 1 or Time == 0 then
GameStatus = "Intermission"
Time = 31
elseif Players >= 2 or Time > 0 then
Time = Time - 1
print(Players)
print(Time)
print(GameStatus)
StatusBar.Text = Time
wait(1)
end
elseif GameStatus == "Intermission" then
GetPlayerCount()
if Players >= 2 or Time > 0 then
Time = Time - 1
print(Players)
print(Time)
print(GameStatus)
StatusBar.Text = "INTERMISSION ".. Time
wait(1)
elseif Players == 50 or Time == 0 then
GameStatus = "InGame"
Time = 300
end
end
end
You’re modifying the contents of StarterGui, which is not what you want.
All instances named Starter... are merely reference containers and their contents are copied to other instances. If you modify contents inside of StarterGui, it will only affect players who load the Gui past the changes.
If a player joins after the event is fired, though, they won’t be able to see the time until the next event is fired. It’s generally better to do what @MayorGnarwhal did because they made it so that there is a maximum 0.99 second delay for the time, but that amount of time is usually taken up by the game’s loading screen anyway. The time will stay updated to all players every single second, so no matter what happens they are all staying up to date with the events.
You could client replicate it with a Value! Try this:
Place a Value in your ReplicatedStorage and a localscript inside your GUI.
--[[SERVER SCRIPT]]--
local val = game.ReplicatedStorage:WaitForChild("Value")
for count = 1, 31
local count = 31
count -= count
val.Value = "Intermission: " .. Time
wait(1)
end
--[[LOCAL SCRIPT]]--
local val = game.ReplicatedStorage:WaitForChild("Value")
val.Changed:Connect(function()
script.Parent.Text = val.Value
end)
You should add a StringValue to the replicated storage and have the text that the Gui should have as the value of the stringvalue. (You can set this at the server.)
You could also put a bool value inside that string where it checks if its ingame or not.
So you do a local script inside the gui you want to do the changes and do Text = StringValue.Value