GUI not working as intended

In my game, at the top of the screen, there is a timer to keep track of the time left in each round. This works at first, but after one round, for one player, the timer sets back to the default “Label”
Here’s my client script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local timeCounter = ReplicatedStorage.Time
local timeUntil = ReplicatedStorage.TimeUntil

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local playerGui = localPlayer:WaitForChild("PlayerGui")
local timerScreen = playerGui:WaitForChild("Timer")
local timerFrame = timerScreen.Timer
local timer = timerFrame.Timer
local timeUntilText = timerFrame.TimeUntil

timer.Text = tostring(timeCounter.Value)
timeUntilText.Text = tostring(timeUntil.Value)

timeCounter.Changed:Connect(function(newValue)
	timer.Text = tostring(newValue)
end)

timeUntil.Changed:Connect(function(newString)
	timeUntilText.Text = tostring(newString)
end)

Here’s my server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local timeCounter = ReplicatedStorage.Time
local timeUntil = ReplicatedStorage.TimeUntil
local gravel = ReplicatedStorage.Gravel
local runners = ReplicatedStorage.Runners
local lobby = ReplicatedStorage.Lobby
local load = ReplicatedStorage.Load

local Players = game:GetService("Players")

local Teams = game:GetService("Teams")
local lobbyTeam = Teams.Lobby
local gravelTeam = Teams.Gravel
local runnersTeam = Teams.Runners

local lobbySpawn = game.Workspace.Lobby.LobbySpawn
local gravelWait = game.Workspace.GravelWaiting.GravelWaiting
local runnerSpawn = game.Workspace.Playground.RunnerSpawn
local gravelSpawn = game.Workspace.Playground.GravelSpawn

while true do
	--intermission
	timeUntil.Value = "Intermission"
	for seconds = 20, 0, -1 do
		timeCounter.Value = seconds
		task.wait(1)
	end
	if #Players:GetPlayers() <= 1 then
		while #Players:GetPlayers() <= 1 do
			timeUntil.Value = "Not enough players."
			task.wait(3)
			timeUntil.Value = "Intermission"
			for seconds = 20, 0, -1 do
				timeCounter.Value = seconds
				task.wait(1)
			end
		end
	end
	--set gravel
	local gravelPlayer = Players:GetPlayers()[math.random(1, #Players:GetPlayers())]
	gravel:FireClient(gravelPlayer)
	gravelPlayer.Team = gravelTeam
	print(gravelPlayer.Name .." is now gravel")
	local gravelChar = gravelPlayer.Character
	if not gravelChar or not gravelChar.Parent then
		gravelPlayer.CharacterAdded:Wait()
	end
	local gravelHrp = gravelChar:WaitForChild("HumanoidRootPart")
	local gravelHumanoid = gravelChar:WaitForChild("Humanoid")
	gravelHrp.CFrame = gravelWait.CFrame
	gravelHumanoid.WalkSpeed = 20
	-- send players to game
	for i, plr in pairs(lobbyTeam:GetPlayers()) do
		runners:FireClient(plr)
		plr.Team = runnersTeam
		local char = plr.Character
		if not char or not char.Parent then
			char.CharacterAdded:Wait()
		end
		local hrp = char:WaitForChild("HumanoidRootPart")
		hrp.CFrame = runnerSpawn.CFrame
	end
	-- headstart
	timeUntil.Value = "Gravel spawns in:"
	for seconds = 30, 0, -1 do
		timeCounter.Value = seconds
		task.wait(1)
	end
	-- start game(this loop is where the break has to be)
	gravelHrp.CFrame = gravelSpawn.CFrame
	timeUntil.Value = "Game in progress."
	for seconds = 300, 0, -1 do
		timeCounter.Value = seconds
		if #runnersTeam:GetPlayers() == 0 then
			break
		end
		task.wait(1)
	end
	-- game over/send to lobby
	timeUntil.Value = "Game Over"
	task.wait(3)
	if #runnersTeam:GetPlayers() >= 1 then
		timeUntil.Value = "Runners Win!"
	else
		timeUntil.Value = "Gravel Wins!"
	end
	gravelHumanoid.WalkSpeed = 16
	for i, plr in pairs(Players:GetPlayers()) do
		plr.Team = lobbyTeam
		lobby:FireClient(plr)
		local char = plr.Character
		if not char or not char.Parent then
			char.CharacterAdded:Wait()
		end
		local hrp = char:WaitForChild("HumanoidRootPart")
		hrp.CFrame = lobbySpawn.CFrame
	end
	task.wait(3)
end

How do I fix this?

1 Like

Check if ResetOnSpawn is checked on in the properties tab for the ScreenGui. It’s most likely checked to true by default. If you see that ResetOnSpawn is checked on then turn it off, and see if that fixes the issue! :slight_smile:

It should look something like this:
image

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.