How to update player gui

doing round base tutorial by roblox

local RoundLengthInSeconds = 60
local IntermissionLengthInSeconds = 20
local RoundStartTime

local function initialize()
	RoundStartTime = tick()
end

while true do
	initialize()	
	repeat
		local currentTime = tick()
		local timeSinceGameStarted = currentTime - RoundStartTime
		game.StarterGui.Round.Frame.TextLabel.Text = math.floor(timeSinceGameStarted)
		wait(0.25)
	until timeSinceGameStarted > RoundLengthInSeconds
	wait(IntermissionLengthInSeconds)
end

I am not fully sure what you are trying to do? Is there an error or something, what are you trying to do?

local RoundLengthInSeconds = 60
local IntermissionLengthInSeconds = 20
local RoundStartTime

local function initialize()
	RoundStartTime = tick()
end

while true do
	initialize()	
	local timeSinceGameStarted = 0
	repeat
		timeSinceGameStarted = tick() - RoundStartTime
		game.StarterGui.Round.Frame.TextLabel.Text = tostring(math.floor(timeSinceGameStarted))
		wait(0.25)
	until timeSinceGameStarted >= RoundLengthInSeconds
	wait(IntermissionLengthInSeconds)
end

I edited my message, check the edited post, it might solve your issues.

StarterGui is replicated across the server-side only, it will not change for any other Player
s GUI’s even if you change a Gui Property

A more simpler approach of doing this would be to create some NumberValues inside ReplicatedStorage, & detect its changes using the Changed event so that it’ll be replicated to every Player’s Gui to change when the NumberValue changes

This is where you made a mistake. First of all, you need to make a script in the ServerScriptService that will do all the math:

-- You'll need to make an RemoteEvent in the ReplicatedStorage
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Change the "YourRemoteEvent" to the name that you set your RemoteEvent to be
local RemoteEvent = ReplicatedStorage.YourRemoteEvent

local RoundLenghtInSeconds = 60
local IntermissionLengthInSeconds = 20
local RoundStartTime

local function initialize()
	RoundStartTime = tick()
end

while true do
	initialize()	
	repeat
		local currentTime = tick()
		local timeSinceGameStarted = currentTime - RoundStartTime

		-- Now this will fire all clients and passes a value that the client can retrieve
		RemoteEvent.FireAllClients(math.floor(timeSinceGameStarted))
		wait(0.25)
	until timeSinceGameStarted > RoundLengthInSeconds
	wait(IntermissionLengthInSeconds)
end

Now you make a LocalScript in your TextLabel with this code:

-- To get the RemoteEvent that you created
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Change the "YourRemoteEvent" to the name that you set your RemoteEvent to be
local RemoteEvent = ReplicatedStorage.YourRemoteEvent

-- Now when the Server Fires the RemoteEvent it will change the clients TextLabel's Text
RemoteEvent:OnClientEvent:Connect(function(value)
	script.Parent.Text = value
end)
`

And that is all it, I hope this was helpful

2 Likes