I am currently making a fairly simple nametag system in my game. I believe that I have done everything correctly, but I cannot seem to get it working.
I have the Billboard GUI in Replicated Storage, and a Server Script in ServerScriptStorage to handle the changes on the nametag.
Here is the Script that handles the Tag:
local rs = game:GetService("ReplicatedStorage")
local tag = rs.Tag
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local head = character:WaitForChild("Head")
local playertag = tag:Clone()
local name = playertag.Name.Text
local cash = playertag.Cash.Text
local rebirths = playertag.Rebirths.Text
playertag.Parent = head
playertag.Adornee = head
name = player.Name
end)
end)
For some reason this script does not work, and I cannot seem to figure out why. I may just be overlooking an issue with the code, but have checked a multiple times and cannot find an issue.
The tag is cloned to the player, but the name does not currently change.
You can’t set the text to a variable. Using the code you have right now you are putting the current text inside the variable so name is most likely empty as the text label is empty. This is pretty hard to explain. What you have to do is set name to playertag.name and then when your setting it you have to use name.Text = player.name. Here is what the script should look like
local rs = game:GetService("ReplicatedStorage")
local tag = rs.Tag
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local head = character:WaitForChild("Head")
local playertag = tag:Clone()
local name = playertag.Name
local cash = playertag.Cash
local rebirths = playertag.Rebirths
playertag.Parent = head
playertag.Adornee = head
name.Text = player.Name
end)
end)
Right this is because every item in the explorer has a property called Name so when you call .Name it thinks your referring to the name of the property. To get around this you could either rename the Name text label or you could do something like this
local name = playertag:FindFirstChild("Name")
--or
local name = playertag["Name"]