Overheadgui not working/showing up

So i tried making a overheadgui so that whenever the player leaves a zone and their boolvalue is false they would get a overheadgui saying “UnAuthorized”, but if the players value is true then they would get an overheadgui saying "Authorized.

This didnt work as it didnt show up. No errors in the output. No nothing. i put the script insdie the zone and it is a serverscript.

Here is the script.

local Zone = script.Parent

function onPartTouched(part)
	local player = Players:GetPlayerFromCharacter(part.Parent)
	if player then
		local IsAuthorized = player:FindFirstChild("IsAuthorized")
		if IsAuthorized and IsAuthorized.Value == true then
			local gui = Instance.new("BillboardGui")
			gui.Parent = player.Character.Head
			gui.Size = UDim2.new(0, 200, 0, 50)
			gui.StudsOffset = Vector3.new(0, 2, 0)

			local label = Instance.new("TextLabel")
			label.Parent = gui
			label.Text = "Authorized"
			label.Font = Enum.Font.Code
			label.FontSize = Enum.FontSize.Size24
			label.TextColor3 = Color3.fromRGB(0, 255, 0)
			label.BackgroundTransparency = 1

			gui.Enabled = true
		else
			local gui = Instance.new("BillboardGui")
			gui.Parent = player.Character.Head
			gui.Size = UDim2.new(0, 200, 0, 50)
			gui.StudsOffset = Vector3.new(0, 2, 0)

			local label = Instance.new("TextLabel")
			label.Parent = gui
			label.Text = "Unauthorized"
			label.Font = Enum.Font.Code
			label.FontSize = Enum.FontSize.Size24
			label.TextColor3 = Color3.fromRGB(255, 0, 0)
			label.BackgroundTransparency = 1

			gui.Enabled = true
		end
	end
end

function onPartLeft(part)
	local player = Players:GetPlayerFromCharacter(part.Parent)
	if player then
		local gui = player.Character.Head:FindFirstChild("BillboardGui")
		if gui then
			gui:Destroy()
		end
	end
end

Zone.Touched:Connect(onPartLeft)
Zone.TouchEnded:Connect(onPartTouched)```

Can anyone possibly help me? I am in very big trouble with this system

assuming that Players have a bool value parented to them:

local Zone = script.Parent
local Players= game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	local gui = Instance.new("BillboardGui")
	gui.Parent = character.Head
	gui.Size = UDim2.new(0, 200, 0, 50)
	gui.StudsOffset = Vector3.new(0, 2, 0)

	local label = Instance.new("TextLabel")
	----
	label.Size = UDim2.new(1,0,1,0)
	----
	label.Parent = gui
	label.Text = "Authorized"
	label.Font = Enum.Font.Code
	label.FontSize = Enum.FontSize.Size24
	label.BackgroundTransparency = 1

	gui.Enabled = false
end)

function onPartTouched(part)
	local player = Players:GetPlayerFromCharacter(part.Parent)
	if player then
		local gui = player.Character.Head:FindFirstChild("BillboardGui")
		gui.Enabled = false
	end

end

function onPartLeft(part)
	local player = Players:GetPlayerFromCharacter(part.Parent)
	if player then
		local IsAuthorized = player:FindFirstChild("IsAuthorized")
		local gui = player.Character.Head.BillboardGui
		gui.Enabled = true
		if IsAuthorized and IsAuthorized.Value == true then
			gui.TextLabel.Text = "Authorized"
			gui.TextLabel.TextColor3 = Color3.fromRGB(0, 255, 0)
		else
			gui.TextLabel.Text = "unauthorized"
			gui.TextLabel.TextColor3 = Color3.fromRGB(255, 0, 4)
		end
	end
end
---
Zone.TouchEnded:Connect(onPartLeft)
Zone.Touched:Connect(onPartTouched)
---

changes

  • Add guis to player when they join so we don’t have to create an delete instances
  • Renamed Functions
  • Scaled the label

Your version works but it adds multiple guis to the player and deletes them all which is not good.