GUIs Not Working

Hey there guys! I’m in a big of a pickle here…

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. ¯_(ツ)_/¯

Thank you very much for helping.

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.

3 Likes

Don’t you gotta update each individual GUI instead of startergui?? I suggest using :FireAllClients

And then in each gui it would be like
game.ReplicatedStorage:WaitForChild(“time”).OnClientEvent:Connect(funtion(time)
script.Parent.Text = tostring(time)
end)

1 Like

One more thing, instead of trying to set Instance.Text to an int, use tostring(value) to set it to a string rather than an int.

Thank you very much! This will be very helpful!

Alright. How would I go about this? Could I have a example of some sort?

I’m pretty sure my example explains???

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.

    repeat
		timeLeft = timeLeft - 1
		game.ReplicatedStorage.RemoteEvent:FireAllClients(timeLeft) 
		wait(1)
	until timeLeft == 0

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.

1 Like

Alrighty then! Thank you very much! You did the scripting for me lol, I guess I owe you now.

1 Like