Why isn't my playerGui text working?

Hello, I’m trying to make a gui that appears when 2 players enter an arena, and it has the ‘kills’ score on it. So far I am able to make the gui appear but it won’t display their kills value for some reason. (the kills ‘value’ isn’t stored, it’s assigned to a variable)

Here is the line that should assign the text:

local ArenaScore = game.StarterGui.ArenaScore
ArenaScore.ScoreBoard.Scores.Text = plr1CurrentKills..":"..plr2CurrentKills

Here is my whole script:

local Players = game:GetService("Players")
local player = game.Players.LocalPlayer

local part1 = workspace.Arena1Player1
local part2 = workspace.Arena1Player2

local team1 = workspace.Arena1Team1
local team2 = workspace.Arena1Team2

local standingOnArena1Player1 = nil
local standingOnArena1Player2 = nil
local ArenaScore = game.StarterGui.ArenaScore
local RemoteEvent = game.ReplicatedStorage:FindFirstChild("RemoteEvent")


local function startEvent()
	local plr1CurrentKills = 0
	local plr2CurrentKills = 0
	
	local SwordGiver = game.ServerStorage.Sword
	
	local plr1 = standingOnArena1Player1
	local plr2 = standingOnArena1Player2
	
	ArenaScore.ScoreBoard.Scores.Text = plr1CurrentKills..":"..plr2CurrentKills
	
	plr1.PlayerGui.ArenaScore.Enabled = true
	plr2.PlayerGui.ArenaScore.Enabled = true
	
	local Sword1 = SwordGiver:Clone()
	local char1 = plr1.Character
	local Sword2 = SwordGiver:Clone()
	local char2 = plr2.Character
	local Arena1Player1Spawn = game.Workspace.Arena1Player1Spawn
	local Arena1Player2Spawn = game.Workspace.Arena1Player2Spawn
	
	local character1Loaded = false
	local character2Loaded = false
	
	
	print("Variables working fine")
	
	
	if char1 or char2 then
		
		
		local humanoid1 = char1:FindFirstChild("Humanoid")
		local humanoid2 = char2:FindFirstChild("Humanoid")
		

		if humanoid1 or humanoid2 then
			
			Sword1.Parent = plr1.Backpack
			humanoid1:EquipTool(Sword1)
			Sword2.Parent = plr2.Backpack
			humanoid2:EquipTool(Sword2)
			
			print("Approved that i'm humanoid")

			local connections = {}

			local function disconnectConnections(kills)
				if kills > 5 then
					for i, v in ipairs(connections) do
						v:Disconnect()
					end

					plr1CurrentKills = 0
					plr2CurrentKills = 0
					part1.Transparency = 0
					part1.CanCollide = true
					part2.Transparency = 0
					part2.CanCollide = true
				end
			end

			connections[1] = plr1.CharacterRemoving:Connect(function(hit)

				local player1 = game.Players:GetPlayerFromCharacter(char1)
				wait(1)
				player1:LoadCharacter()
				char1 = player1.Character
				local humanoid1 = char1.Humanoid

				plr2CurrentKills = plr2CurrentKills + 1

				disconnectConnections(plr2CurrentKills) -- will check the kills and disconnect connections if it's over 5

				char2.Humanoid.Health = 100

				Sword1.Parent = player1.Backpack
				humanoid1:EquipTool(Sword1)

				char2.HumanoidRootPart.CFrame = CFrame.new(
					Arena1Player2Spawn.Position
				)
				char1.HumanoidRootPart.CFrame = CFrame.new(
					Arena1Player1Spawn.Position
				)
			end)
			connections[2] = plr2.CharacterRemoving:Connect(function(hit)

				local player2 = game.Players:GetPlayerFromCharacter(char2)
				wait(1)
				player2:LoadCharacter()
				char2 = player2.Character
				local humanoid2 = char2.Humanoid


				plr1CurrentKills = plr1CurrentKills + 1

				disconnectConnections(plr1CurrentKills) -- will check the kills and disconnect connections if it's over 5

				char1.Humanoid.Health = 100

				Sword2.Parent = player2.Backpack
				humanoid2:EquipTool(Sword2)

				char1.HumanoidRootPart.CFrame = CFrame.new(
					Arena1Player1Spawn.Position
				)
				char2.HumanoidRootPart.CFrame = CFrame.new(
					Arena1Player2Spawn.Position
				)
			end)
		end
	end		
end

RemoteEvent.OnServerEvent:Connect(function() -- if any player presses the play button, executes event
	if standingOnArena1Player2 ~= nil and standingOnArena1Player1 ~= nil then
		--Hide playbutton gui
		standingOnArena1Player2.PlayerGui.ScreenGui.Enabled = false
		standingOnArena1Player1.PlayerGui.ScreenGui.Enabled = false
		--Teleports
		workspace[standingOnArena1Player1.Name].HumanoidRootPart.CFrame = CFrame.new(team1.Position.X,team1.Position.Y,team1.Position.Z)
		workspace[standingOnArena1Player1.Name].HumanoidRootPart.CFrame *= CFrame.Angles(0, math.rad(90), 0)
		workspace[standingOnArena1Player2.Name].HumanoidRootPart.CFrame = CFrame.new(team2.Position.X,team2.Position.Y,team2.Position.Z)
		workspace[standingOnArena1Player2.Name].HumanoidRootPart.CFrame *= CFrame.Angles(0, math.rad(270), 0)
		local gameRunning = true
		part1.Transparency = 1
		part1.CanCollide = false
		part2.Transparency = 1
		part2.CanCollide = false
		startEvent() -- triggers function
	end
end)


-----------------------------------------------------

--				PART1 Events				 --

-----------------------------------------------------

-- Touched functions [Events now set each part that was touched to the players name instead of the opposite button]

part1.Touched:Connect(function(TouchedPart) -- Touched

	local Player = Players:GetPlayerFromCharacter(TouchedPart.Parent)

	if Player then -- Check if it found character
		if standingOnArena1Player1 == nil then -- Check if not standing and if not occupied

			part1.BrickColor = BrickColor.new("Teal") -- Set color
			standingOnArena1Player1 = Player
		end	
	end
end)

part1.TouchEnded:Connect(function(TouchedPart)

	local Player = Players:GetPlayerFromCharacter(TouchedPart.Parent)

	if Player then -- Check if it found character
		if standingOnArena1Player1 ~= nil then -- Check if standing and is occupied
			if  standingOnArena1Player1.PlayerGui.ScreenGui.Enabled == true then
				standingOnArena1Player1.PlayerGui.ScreenGui.Enabled = false
			end
			part1.BrickColor = BrickColor.new("Smoky grey") -- Set color
			standingOnArena1Player1 = nil

			if standingOnArena1Player2 ~= nil then
				if standingOnArena1Player2.PlayerGui.ScreenGui.Enabled == true then
					standingOnArena1Player2.PlayerGui.ScreenGui.Enabled = false
				end
			end
		end	
	end
end)

-----------------------------------------------------

--				PART2 Events				 --

-----------------------------------------------------

part2.Touched:Connect(function(TouchedPart) -- Touched

	local Player = Players:GetPlayerFromCharacter(TouchedPart.Parent)

	if Player then -- Check if it found character
		if standingOnArena1Player2 == nil then -- Check if not standing and if not occupied

			part2.BrickColor = BrickColor.new("Teal") -- Set color
			standingOnArena1Player2 = Player
		end	
	end
end)

part2.TouchEnded:Connect(function(TouchedPart)

	local Player = Players:GetPlayerFromCharacter(TouchedPart.Parent)

	if Player then -- Check if it found character
		if standingOnArena1Player2 ~= nil then -- Check if standing and is occupied
			if   standingOnArena1Player2.PlayerGui.ScreenGui.Enabled == true then
				standingOnArena1Player2.PlayerGui.ScreenGui.Enabled = false
			end
			part2.BrickColor = BrickColor.new("Smoky grey") -- Set color
			standingOnArena1Player2 = nil

			if standingOnArena1Player1 ~= nil then
				if  standingOnArena1Player1.PlayerGui.ScreenGui.Enabled == true then
					standingOnArena1Player1.PlayerGui.ScreenGui.Enabled = false
				end
			end
		end	
	end
end)

while task.wait(0) do
	if standingOnArena1Player2 ~= nil and standingOnArena1Player1 ~= nil then -- checks if both players are on top
		standingOnArena1Player2.PlayerGui.ScreenGui.Enabled = true
		standingOnArena1Player1.PlayerGui.ScreenGui.Enabled = true
	end
end

you’re trying to change game.StarterGui.ArenaScore which is what is replicated to game.Players[PLAYER].PlayerGui upon joining/spawning

a simple fix should be local ArenaScore = game.Players.LocalPlayer.PlayerGui.ArenaScore (assuming that this was all done on the client)

1 Like

This seemed to break my script for some reason, i’m not sure if I put it in the wrong place or something?

wait is this a local script or not? i’m confused because you have game.Players.LocalPlayer but also stuff to do with cloning, changing parents and serverstorage

1 Like

This is a server script, I can’t remember why I have local player, it’s possible it has no function in my script.

Try replacing this with

local ArenaScore = player.PlayerGui.ArenaScore
1 Like

Thanks, it’s working now, the only problem is I would like it to update the score for both players gui when one of the players die. But i’m not sure how to incorporate this into my script…
Here is my script:

local function startEvent()

	local plr1CurrentKills = 0
	local plr2CurrentKills = 0

	local SwordGiver = game.ServerStorage.Sword

	local plr1 = standingOnArena1Player1
	local plr2 = standingOnArena1Player2
	
	local ArenaScore1 = plr1.PlayerGui.ArenaScore
	local ArenaScore2 = plr2.PlayerGui.ArenaScore
	
	ArenaScore1.ScoreBoard.Scores.Text = plr1CurrentKills..":"..plr2CurrentKills
	ArenaScore2.ScoreBoard.Scores.Text = plr1CurrentKills..":"..plr2CurrentKills
	
	ArenaScore1.Enabled = true
	ArenaScore2.Enabled = true

	local Sword1 = SwordGiver:Clone()
	local Sword2 = SwordGiver:Clone()
	local char1 = plr1.Character
	local char2 = plr2.Character
	local Arena1Player1Spawn = game.Workspace.Arena1Player1Spawn
	local Arena1Player2Spawn = game.Workspace.Arena1Player2Spawn

	local character1Loaded = false
	local character2Loaded = false


	print("Variables working fine")


	if char1 or char2 then


		local humanoid1 = char1:FindFirstChild("Humanoid")
		local humanoid2 = char2:FindFirstChild("Humanoid")


		if humanoid1 or humanoid2 then

			Sword1.Parent = plr1.Backpack
			humanoid1:EquipTool(Sword1)
			Sword2.Parent = plr2.Backpack
			humanoid2:EquipTool(Sword2)

			print("Approved that i'm humanoid")

			local connections = {}

			local function disconnectConnections(kills)
				if kills > 5 then
					for i, v in ipairs(connections) do
						v:Disconnect()
					end

					plr1CurrentKills = 0
					plr2CurrentKills = 0
					part1.Transparency = 0
					part1.CanCollide = true
					part2.Transparency = 0
					part2.CanCollide = true
				end
			end

			connections[1] = plr1.CharacterRemoving:Connect(function(hit)

				local player1 = game.Players:GetPlayerFromCharacter(char1)
				wait(1)
				player1:LoadCharacter()
				char1 = player1.Character
				local humanoid1 = char1.Humanoid

				plr2CurrentKills = plr2CurrentKills + 1

				disconnectConnections(plr2CurrentKills) -- will check the kills and disconnect connections if it's over 5

				char2.Humanoid.Health = 100

				Sword1.Parent = player1.Backpack
				humanoid1:EquipTool(Sword1)

				char2.HumanoidRootPart.CFrame = CFrame.new(
					Arena1Player2Spawn.Position
				)
				char1.HumanoidRootPart.CFrame = CFrame.new(
					Arena1Player1Spawn.Position
				)
			end)
			connections[2] = plr2.CharacterRemoving:Connect(function(hit)
				
				local player2 = game.Players:GetPlayerFromCharacter(char2)
				wait(1)
				player2:LoadCharacter()
				char2 = player2.Character
				local humanoid2 = char2.Humanoid
				
				plr1CurrentKills = plr1CurrentKills + 1

				disconnectConnections(plr1CurrentKills) -- will check the kills and disconnect connections if it's over 5

				char1.Humanoid.Health = 100

				Sword2.Parent = player2.Backpack
				humanoid2:EquipTool(Sword2)

				char1.HumanoidRootPart.CFrame = CFrame.new(
					Arena1Player1Spawn.Position
				)
				char2.HumanoidRootPart.CFrame = CFrame.new(
					Arena1Player2Spawn.Position
				)
			end)
		end
	end		
end

1 Like

You can put this line whenever you want to update the scores, and to detect when the a character has died, you can put it into a Humanoid.Died event.

1 Like