Timing System UI Errors

Hi, I’m making a race timing system and the script can be seen below. All the print statements print completely fine, and the script manages to add the player to the board, but it doesn’t seem to be changing the TextLabel properties.

-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- RemoteEvents
local UpdateBoard = ReplicatedStorage:FindFirstChild("TimingEvents").UpdateBoard

-- GUI
local GUI = script.Parent
local TimingFrame = GUI.Frame.TimingFrame
local Template = TimingFrame.NameBoard

-- Default time
local Lap1 = 0
local Lap2 = 0
local Lap3 = 0
local Final = 0

UpdateBoard.OnClientEvent:Connect(function(Player, Lap, Time)
	
	local PlayerBoard = TimingFrame.NameBoard:Clone() -- Add player to timing board
	local TimeUI = PlayerBoard.Times
	
	if Lap == "AddPlayer" then
		PlayerBoard.Name = Player
		PlayerBoard.Times.Username.Text = tostring(Player)
		PlayerBoard.Parent = TimingFrame
		PlayerBoard.Visible = true
		
	elseif Lap == "Lap1" then
		Lap1 = tostring(math.round(Time*100)/100)
		TimeUI.Time1.Text = Lap1
		TimeUI.Lap1.BackgroundColor3 = Color3.new(0, 255, 0)
		TimeUI.Time1.Visible = true
		print(Lap1)
		
	elseif Lap == "Lap2" then
		Lap2 = tostring(math.round(Time*100)/100)
		TimeUI.Time2.Text = Lap2
		TimeUI.Lap2.BackgroundColor3 = Color3.new(0, 255, 0)
		TimeUI.Time2.Visible = true
		print(Lap2)
	elseif Lap == "Lap3" then
		Lap3 = tostring(math.round(Time*100)/100)
		Final = tostring(math.round((Lap1 + Lap2 + Lap3) *100)/100)
		TimeUI.Time3.Text = Lap3
		TimeUI.TotalTime.Text = Final
		TimeUI.Lap3.BackgroundColor3 = Color3.new(0, 255, 0)
		TimeUI.Time3.Visible = true
		print(Lap3)
		print(Final)
	end
end)

It is because TimeUI is falling out of scope each time the event runs.

UpdateBoard.OnClientEvent:Connect(function(Player, Lap, Time)
	
	if Lap == "AddPlayer" then
		local PlayerBoard = TimingFrame.NameBoard:Clone() -- Add player to timing board
		PlayerBoard.Name = Player
		PlayerBoard.Times.Username.Text = tostring(Player)
		PlayerBoard.Parent = TimingFrame
		PlayerBoard.Visible = true
	else
		local TimeUI = TimingFrame:FindFirstChild(Player).Times -- This should find the existing playerboard
		
		if Lap == "Lap1" then
			Lap1 = tostring(math.round(Time*100)/100)
			TimeUI.Time1.Text = Lap1
			TimeUI.Lap1.BackgroundColor3 = Color3.new(0, 255, 0)
			TimeUI.Time1.Visible = true
			print(Lap1)
			
		elseif Lap == "Lap2" then
			Lap2 = tostring(math.round(Time*100)/100)
			TimeUI.Time2.Text = Lap2
			TimeUI.Lap2.BackgroundColor3 = Color3.new(0, 255, 0)
			TimeUI.Time2.Visible = true
			print(Lap2)
		elseif Lap == "Lap3" then
			Lap3 = tostring(math.round(Time*100)/100)
			Final = tostring(math.round((Lap1 + Lap2 + Lap3) *100)/100)
			TimeUI.Time3.Text = Lap3
			TimeUI.TotalTime.Text = Final
			TimeUI.Lap3.BackgroundColor3 = Color3.new(0, 255, 0)
			TimeUI.Time3.Visible = true
			print(Lap3)
			print(Final)
		end
	end
end)

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