My nametag script doesnt work

–The script:

local player = game.Players.LocalPlayer
local leaderstats = game.Players.leaderstats
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		if player.leaderstats.Wins.Value >= 100 then
			script.SkilledTag:Clone().Parent = char.Head
		end
	end)
end)

As you can see, billboardgui for tag is put inside the script:
immagine_2023-02-07_134548154

Basically I want that when the player achieves 100 wins, he has the tag above his head.

(I’m new to roblox scripting so be patient)

1 Like
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
       local leaderstats = plr.leaderstats
		if plr.leaderstats.Wins.Value >= 100 then
			script.SkilledTag:Clone().Parent = char.Head
		end
	end)
end)

In server scripts, you cannot define the player with game.Players.LocalPlayer.

The way to get the player in a server script is to pass them through the PlayerAdded event like you have done already.

2 Likes

Alright I will improve your code.

First of all, you are checking the players wins only once.

You could add for example .Changed to constantly return the players wins to do this.

Code:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
       local leaderstats = plr:WaitForChild("leaderstats")
       leaderstats.Wins.Changed:Connect(function(wins)
		if wins >= 100 then
			script.SkilledTag:Clone().Parent = char.Head
		end
              end)
	end)
end)
2 Likes

Wouldn’t it be Wins.Value and not wins?

2 Likes

No. It’s basically like localizing something.

You could do that but it’s a better way to make code cleaner.

I’ll show you an image for example.

1 Like

Understood! I always tend to use GetPropertyChangedSignal() and pass through Value, makes sense. Thank you.

2 Likes

That is great to use if you want to know what property is being changed!

If you would like to read more about this then here is an link.

2 Likes

First of all thank you all for the help. I tested it out but does not seem to work.
Here is the output error:
immagine_2023-02-07_135853600

Could you try this? And also, what is the name of your Wins value? I do not know what it is so it could be an error because it does not exist.

game.Players.PlayerAdded:Connect(function(player)
	local wins = player:WaitForChild("leaderstats"):WaitForChild("Wins")
	
	
	player.CharacterAdded:Connect(function(char)
		wins.Changed:Connect(function(yea)
			if yea >= 100 then
				script.SkilledTag:Clone().Parent = char:WaitForChild("Head")
			end
		end)
	end)
end)
1 Like

The name is Wins as tiped in the script

I tried this aswell but it doesnt work. Now i have no errors in the output

Try giving yourself 100 wins. It could work

1 Like

you are right. I changed my Wins value from 80M to 100 and it worked.

No problem! Make sure to Solution any code that works. It makes people that research know that this has been approved by the person finding help, making it more easier for the people trying to find a script that works. I can tell you are new to devforum so take these tips to mind.

2 Likes

thank you for your time i really appreciate it

  1. Exploiters can change their value on the client-side and get the name tag.
  2. No one else will be able to see the name tag, only the affected player.
  3. Change this to a server script to fix the issues above.

Keep in mind that the LocalPlayer does not exist on the server.
You’ll need to use the plr parameter which is automatically passed to Players.PlayerAdded.

1 Like

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