Script doesn't work

  1. What do you want to achieve? A working script

  2. What is the issue? It doesn’t work

  3. What solutions have you tried so far? Adjusting the code

if script.Parent.Parent.Teams == "Military Police" then
	game.Players.PlayerAdded:Connect(function(Player)
		Player.CharacterAdded:Connect(function(Character)
			local GuiClone = script.OverheadGui:Clone()
			GuiClone.Parent = Character.Head

			local InformationLabel = GuiClone.InfoLabel

			InformationLabel.Text = Player.Name ..'Military Police'
		end)
	end)
end


This code doesn’t work. I’m trying to make a rank appear above someone’s head if they are in a team please help thank you!

So much wrong stuff. No.

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if plr.Team == "Military Police" then
local GuiClone = script.OverheadGui:Clone()
GuiClone.Parent = Character.Head
local InformationLabel = GuiClone.InfoLabel
InformationLabel.Text = Player.Name..' Military Police'
end
end)
end)

sorry im new to coding and am trying to learn with every mistake i make

Okay, so does the code work? Or not?

no there are 2 undefined variables

where’s the error? I wrote this on mobile.

character and player in lines 5 and 7

That’s easy, just a seccccccccc

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if plr.Team == "Military Police" then
local GuiClone = script.OverheadGui:Clone()
GuiClone.Parent = char.Head
local InformationLabel = GuiClone.InfoLabel
InformationLabel.Text = plr.Name..' Military Police'
end
end)
end)
1 Like

It doesn’t work no errors but the overhead gui doesn’t appear

Could you show us the overhead GUI properties?



Ill brb in about 10 -15 mins @regexman

Check “always ontop” to true m

1 Like

@regexman it still doesn’t work.

Have you tried setting the Adornee the the chars head?

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if plr.Team == "Military Police" then
local GuiClone = script.OverheadGui:Clone()
GuiClone.Parent = char.Head
GuiClone.Adornee = char.Head
local InformationLabel = GuiClone.InfoLabel
InformationLabel.Text = plr.Name..' Military Police'
end
end)
end)

@regexman still doesn’t work

is the script a server script. If so where is it located?

Put this script inside the serverscriptservice and put the nametag in the script.


game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local GuiClone = script.OverheadGui:Clone()
        local InformationLabel = GuiClone.InfoLabel
        if Player.Team == game.Teams["Military Police"] then
             

		     InformationLabel.Text = Player.Name ..'Military Police'
        end
		GuiClone.Parent = Character.Head

		
	end)
end)

Please tell me, what exactly SHOULD this do and where is the script located?

The script is in server script service it is a local script, it should display your name and team name. It currently diplays half my name and is glued on to my face.