So I’m working on a round based game and I ran into this. My GUIs aren’t doing what their supposed to! What I want it to do is simple, say when the Game is in progress and when its an intermission. There is also another bar for time that I don’t understand why its not working either.
(It runs the first line of GUI code fine, but it stops afterward.)
local gameRoundLengthInSeconds = 10
local intermissionLengthInSeconds = 5
local timeLeft
local TimeGUIs = game.StarterGui.GUI.TimeLeft
local function initialize()
timeLeft = gameRoundLengthInSeconds
end
while true do
initialize()
print("Game Starting!")
TimeGUIs.IntermissionTimeLeft.Text = "Time Left:"
repeat
timeLeft = timeLeft - 1
TimeGUIs.Time.Text = timeLeft
wait(1)
until timeLeft == 0
TimeGUIs.IntermissionTimeLeft.Text = "Intermission:"
print("Intermission...")
wait(intermissionLengthInSeconds)
end
I’ve tried to rewrite it, and ended up with nothing. This is probably a noobie mistake but, I dunno. ¯_(ツ)_/¯
You are changing the GUI in startergui. You need to change it in playergui since that is where the player actually sees them. StarterGui clones to the player as soon as they join, but playergui actually replicates changes.
And then in each gui it would be like
game.ReplicatedStorage:WaitForChild(“time”).OnClientEvent:Connect(funtion(time)
script.Parent.Text = tostring(time)
end)
You could use what @JackStrauss said by using FireAllClients, which would be pretty effective. You could just use a for loop and loop through the player’s PlayerGui’s, but you would need to use a server script, and it is always better to change GUIs through local scripts. What you would need to do is just do FireAllClients everytime the timer value changes, and in a local script, do OnClientEvent and have that change the text of the GUI.
Now, for what you have, you would probably just include the FireAllClients inside of the repeat loop, but, in the local script that connect onclientevent, you would also want to change the text to intermission. I know im rambling, so let me show you what it could look like.
And you would need to make a local script somewhere where it clones to the player, such as: StarterGui, or any of the starterplayer locations.
Local script:
local player = game.Players.LocalPlayer
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(timeLeft)
if timeLeft == 0 then
player.PlayerGui.GUI.TimeLeft.Text = "Intermission..."
else
player.PlayerGui.GUI.TimeLeft.Text = tostring(timeLeft)
end
end)
This should work, but if there are errors I’ll be happy to fix them.