Why code isn't working?

local RP = game:GetService("ReplicatedStorage")
local PlayerTags = RP.PlayerTags
local player = game:GetService("Players")
local PoliceLevel = player:GetChildren("leaderstats").PoliceLevel
local CriminalLevel = player:GetChildren("leaderstats").CriminalLevel

game:WaitForChild("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local head = char.Head
		local PlayerLevelText = PlayerTags.PlayerLevelText
		local PlayerNameText = PlayerTags.PlayerNameText
		
		PlayerTags.Parent = head
		PlayerTags.Adornee = head
		if player.Team == "Criminal" then
			PlayerLevelText.Text = "Lv: "..player.CriminalLevel.Value

		elseif player.Team == "Police" then
			PlayerLevelText.Text = "Lv:"..player.PoliceLevel.Value
		end
		
		PlayerNameText.Text = player.Name
		
	end)
end)

I want when the player is in the police team, the text will be equals his level in that team. And so when he’s in criminal, but it doesn’t work for some reason, even no errors

These lines dont make sense.
player represents here a service, not the local player.

Try this code:

local RP = game:GetService("ReplicatedStorage")
local PlayerTags = RP.PlayerTags
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local head = char.Head
		local PlayerLevelText = PlayerTags.PlayerLevelText:Clone()
		local PlayerNameText = PlayerTags.PlayerNameText:Clone()
		PlayerTags.Parent = head
		PlayerTags.Adornee = head

		if player.Team == Teams:FindFirstChild("Criminals") then
			PlayerLevelText.Text = "Lv: "..player.CriminalLevel.Value
		elseif player.Team == Teams:FindFirstChild("Police") then
			PlayerLevelText.Text = "Lv:"..player.PoliceLevel.Value
		end
		PlayerNameText.Text = player.Name
	end)
end)

I also believe you’d have to clone those Tags into each player when they join the game.

1 Like

I have the billboard in the RP so it will clone for each player. The code you sent still doesn’t work either.

1 Like

Try debugging by using prints inside the characteradded event, to see whats wrong.

1 Like

“Prints” ? I never debugged before … Maybe once but I forgot.

1 Like

like print("hello world"), try to print some values/names, to see if you get errors.

1 Like

Try this-

local RP = game:GetService("ReplicatedStorage")
local PlayerTags = RP.PlayerTags
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

Players.PlayerAdded:Connect(function(player)
    print(player.Name.." has arrived")
	player.CharacterAdded:Connect(function(char)
        print(char.Name.." has arrived in the world")
		local head = char.Head
		local PlayerLevelText = PlayerTags.PlayerLevelText:Clone()
		local PlayerNameText = PlayerTags.PlayerNameText:Clone()
		PlayerTags.Parent = head
		PlayerTags.Adornee = head
        print("Success")
		if player.Team == Teams:FindFirstChild("Criminals") then
			PlayerLevelText.Text = "Lv: "..player.CriminalLevel.Value
		elseif player.Team == Teams:FindFirstChild("Police") then
			PlayerLevelText.Text = "Lv:"..player.PoliceLevel.Value
		end
		PlayerNameText.Text = player.Name
	end)
end)
1 Like

I see the problem:

PlayerTags.Parent = head
PlayerTags.Adornee = head

Since, local PlayerTags = RP.PlayerTags represents a folder[ I assume], or a model.
It doesnt have an Adornee property.
To fix that, try this -

local RP = game:GetService("ReplicatedStorage")
local PlayerTags = RP.PlayerTags
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

Players.PlayerAdded:Connect(function(player)
    print(player.Name.." has arrived")
	player.CharacterAdded:Connect(function(char)
        print(char.Name.." has arrived in the world")
		local head = char.Head
		local PlayerLevelText = PlayerTags.PlayerLevelText:Clone()
		local PlayerNameText = PlayerTags.PlayerNameText:Clone()
	    PlayerLevelText .Parent = head
        PlayerNameText .Parent = head
		PlayerLevelText .Adornee = head
        PlayerNameText .Adornee = head
        print("Success")
		if player.Team == Teams:FindFirstChild("Criminals") then
			PlayerLevelText.Text = "Lv: "..player.CriminalLevel.Value
		elseif player.Team == Teams:FindFirstChild("Police") then
			PlayerLevelText.Text = "Lv:"..player.PoliceLevel.Value
		end
		PlayerNameText.Text = player.Name
	end)
end)

Tho, I suggest having 1 tag, containing 2 textlabels/frames,etc and name of PlayerNameText, and the other PlayerLevelText.

1 Like

I mean, I just don’t know why it won’t just print in the next tag the player team level value. It prints the text in the properties but not in the script for some reason.

2 Likes

Try this, do all of those prints print out?

1 Like

Yes, all of them and still. It’s so weird. I’m also not sure if I put the texts in its Billboard the level text still won’t work.

1 Like

I fixed it, it’s so freaking wierd.

1 Like