I’ve implemented a nametag into my game and modified it by adding a TextLabel. I was thinking of making the TextLabel display a leaderstat in the game called “Deaths,” which represents the player’s number of deaths.
However, I’m having trouble finding the value. It turns out the “Deaths” value is located in the local player or client, within a folder created with Instance.new called “leaderstats.” Here’s an image to better illustrate:
As you can clearly see, that’s where it’s located. The issue here is that I want to accomplish this from the script that inserts the nametag into the character, but I don’t know how to reach the local player and locate that value to display it in the TextLabel. Here’s an image of the location of the script that inserts the nametag into the player:
This is what’s inside that script :
wait(0.1)
local char = script.Parent
local player = game.Players:GetPlayerFromCharacter(char)
local groupid = 1234567890 -- ADD YOUR GROUP ID HERE
local UserInputService = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")
local images = {
PC = "rbxassetid://4728059490",
Mobile = "rbxassetid://4728060256",
Console="rbxassetid://4728059072"
}
local tag = game.ServerStorage.RankTag:Clone()
local image = game.ServerStorage.DeviceGuiBilboard:Clone()
print("asd")
local name = tag.Frame.plrn
local label = tag.Frame.plrr
tag.Parent = char:WaitForChild("HumanoidRootPart")
tag.Adornee = char:WaitForChild("HumanoidRootPart")
image.Parent = char:WaitForChild("HumanoidRootPart")
image.Adornee = char:WaitForChild("HumanoidRootPart")
game.ReplicatedStorage.CheckDevice.OnServerEvent:Connect(function(player, device)
image.ImageLabel.Image = images[device]
print(device)
end)
name.Text = player.Name
label.Text = player:GetRoleInGroup(groupid)
In summary, I want to locate the value named “Deaths” so that the text on the nametag displays it, something like this:
-- THIS IS AN EXAMPLE DONT USE IT
Ranktag.Textlabel.Text = Deaths.Value
Thank you for your attention, and I look forward to your assistance!
If the name tag is created on the server (NameTagScript) and just change the texts on the name tag then you don’t even need to access the client, just use the name tag directly.
Also you can use the player.leaderstats.Deaths value to get the amount of deaths the player has in the rank tag script
In case you want to update the values, just connect GetPropertyChangedSignal() on the deaths value and update it
Sorry I don’t really understand that… but if you are doing this on server, try creating a script, not a LocalScript, and change the RunContext of the script (found in the properties) to Client. It should look something like this:
Example or reference:
while not game:IsLoaded() do
task.wait()
end
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer::Player
local leaderstats = plr:WaitForChild("leaderstats")
local deaths = leaderstats:FindFirstChild("Deaths").Value -- check for the death stat
local deathText = pathToDeathTextHere -- where your death text is (example: script.Parent.DeathText)
deathText = `{tostring(deaths)}`
You need to change the deathText variable to the pathway of your death count (TextLabel) object in the character.
It’s not that, I just want in this script located in startercharacterscripts to be able to locate the player client and find the leadersstats folder.
wait(0.1)
local char = script.Parent
local player = game.Players:GetPlayerFromCharacter(char)
local groupid = 1234567890 -- ADD YOUR GROUP ID HERE
local UserInputService = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")
local images = {
PC = "rbxassetid://4728059490",
Mobile = "rbxassetid://4728060256",
Console="rbxassetid://4728059072"
}
local tag = game.ServerStorage.RankTag:Clone()
local image = game.ServerStorage.DeviceGuiBilboard:Clone()
print("asd")
local name = tag.Frame.plrn
local label = tag.Frame.plrr
tag.Parent = char:WaitForChild("HumanoidRootPart")
tag.Adornee = char:WaitForChild("HumanoidRootPart")
image.Parent = char:WaitForChild("HumanoidRootPart")
image.Adornee = char:WaitForChild("HumanoidRootPart")
game.ReplicatedStorage.CheckDevice.OnServerEvent:Connect(function(player, device)
image.ImageLabel.Image = images[device]
print(device)
end)
name.Text = player.Name
label.Text = player:GetRoleInGroup(groupid)