Hi! So I have this leaderstats script that clones the nametag in replicated storage onto the player:
ame.Players.PlayerAdded:Connect(function(plr)
local toolsOwned = {}
local stylesOwned = {}
local titlesOwned = {}
local style = ""
local title = ""
local coins = 0
local wins = 0
local skips = 0
local packedData;
local s, err = pcall(function()
packedData = ds:GetAsync(plr.UserId)
end)
if s then
plr:SetAttribute('DataSuccess', true)
else
print(tostring(err))
end
if packedData then
local s = pcall(function()
packedData = game.HttpService:JSONDecode(packedData)
end)
if typeof(packedData) == 'table' then
stylesOwned = packedData.Styles or stylesOwned
titlesOwned = packedData.Titles or titlesOwned
toolsOwned = packedData.Tools or toolsOwned
coins = packedData.Coins or coins
wins = packedData.Wins or wins
skips = packedData.Skips or skips
title = packedData.Title or title
else
plr:SetAttribute('DataSuccess', false)
end
end
print(3)
if not plr:GetAttribute('DataSuccess') then
-- notify the player that their data did not load successfully.
local msg = Instance.new('Message')
msg.Name = '__ALEXSMESSAGE'
msg.Text = 'Failed to load your data. Please rejoin.'
msg.Parent = plr:WaitForChild('PlayerGui')
game.Debris:AddItem(msg, 5)
end
print(4)
local ls = Instance.new("Folder", plr)
ls.Name = "leaderstats"
local coinsValue = Instance.new("IntValue", ls)
coinsValue.Name = "Coins"
coinsValue.Value = coins
local winsValue = Instance.new("IntValue", ls)
winsValue.Name = "Wins"
winsValue.Value = wins
local skipsValue = Instance.new("IntValue", ls)
skipsValue.Name = "Skips"
skipsValue.Value = skips
local previoustitle = Instance.new("StringValue", plr)
previoustitle.Name = "previoustitle"
previoustitle.Value = title
local previousstyle = Instance.new("StringValue", plr)
previousstyle.Name = "previousstyle"
previousstyle.Value = style
print(5)
plr.CharacterAdded:Connect(function(char)
--Varibles
local head = char.Head
local newtext = nametag:Clone()
local uppertext = newtext:WaitForChild("PlayerName")
local lowertext = newtext.Title
local humanoid = char.Humanoid
print(6)
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None -- use enum instead of a string
--Main Text
newtext.Parent = head
newtext.Adornee = head
uppertext.Text = plr.Name
if plr.previoustitle.Value ~= "" then
lowertext.Text = plr.previoustitle.Value
end
--"If" Statements
--You can add as many of these as you wish, just change it to the player's name.
end)
print(7)
plr.CharacterRemoving:Connect(function()
title = plr.Character.Head.Nametag.Title.Text
end)
local ownedFolder2 = Instance.new("Folder", plr)
ownedFolder2.Name = "OwnedTools"
local ownedFolder3 = Instance.new("Folder", plr)
ownedFolder3.Name = "OwnedTitles"
local ownedFolder4 = Instance.new("Folder", plr)
ownedFolder4.Name = "OwnedStyles"
for i, owned in pairs(toolsOwned) do
if tools:FindFirstChild(owned) then
tools[owned]:Clone().Parent = ownedFolder2
end
end
for i, owned in pairs(titlesOwned) do
if titles:FindFirstChild(owned) then
titles[owned]:Clone().Parent = ownedFolder3
end
end
for i, owned in pairs(stylesOwned) do
if titles:FindFirstChild(owned) then
titles[owned]:Clone().Parent = ownedFolder3
end
end
end)
Here is the part that clones:
plr.CharacterAdded:Connect(function(char)
--Varibles
local head = char.Head
local newtext = nametag:Clone()
local uppertext = newtext:WaitForChild("PlayerName")
local lowertext = newtext.Title
local humanoid = char.Humanoid
print(6)
humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None -- use enum instead of a string
--Main Text
newtext.Parent = head
newtext.Adornee = head
uppertext.Text = plr.Name
if plr.previoustitle.Value ~= "" then
lowertext.Text = plr.previoustitle.Value
end
--"If" Statements
--You can add as many of these as you wish, just change it to the player's name.
end)
print(7)
plr.CharacterRemoving:Connect(function()
title = plr.Character.Head.Nametag.Title.Text
end)
There is one major flaw with it which is the nametag doesn’t clone for the 2nd, 3rd, 4th, etc person in-game. Only the first person who joins the server will have the nametag on their head. I tried to debug it by putting a print statement in the CharacterAdded function and it printed for the 2nd player which means the function is happening but it isn’t cloning. How can I fix this?