I’m trying to make a Part display a players leaderstats. I already have a leaderstats script, I just need help on making the part display a players leaderstats.
I don’t know what part of the leaderstats you want to display on the part, but we will just use ‘cash’ as an example here. (I HAVENT TESTED THIS SCRIPT SO I DONT KNOW IF IT WORKS)
Go ahead and add a SurfaceGui to the part. This will create a GUI on the part. Then add a TextLabel in the SurfaceGui so it can display your desired values. Then go in the properties of the gui and make sure the gui is facing the right way by changing the facing direction thingy. Once you have done that you can put in a local script in the gui and paste this:
local text = game.Workspace.Part.SurfaceGui.TextLabel -- change this to the actual path of the TextLabel
local player = game.Players.LocalPlayer -- gets the localplayer
local leaderstats = player.leaderstats -- change if needed
text.Text = leaderstats.Cash.Value -- sets the text of the TextLabel to the value of the 'Cash' value in ur leaderstats
I just tried that script and it didn’t work.
We need more info, show us how the leadestats are laid out while testing in studio
Here is my current leaderstats script.
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
local Score = Instance.new("IntValue")
Score.Name = "Score"
Score.Parent = leaderstats
Score.Value = 0
end)
Make a part in workspace called ShowStats
, with a BillboardGui under it. Place a TextLabel under the BillboardGui.
local Label = workspace.ShowStats.BillboardGui.TextLabel
game.Players.PlayerAdded:Connect(function(Player)
-- leaderstats here
TextLabel.Text = Cash.Value
end)
If you’re using a local script:
local Label = workspace.ShowStats:WaitForChild('BillboardGui').TextLabel
Label.Text = game.Players.LocalPlayer:WaitForChild('leaderstats').Cash.Value
Hmm… it didn’t seem to work for me.
Could you show me your explorer and script?
Maybe you could elaborate more:
- What do you mean by displaying the leaderstats?
- What GuiObject do you want to use?: BillboardGui, SurfaceGui.
Since it is GUI, there is probably many ways to display the data.
More likely:
- What part of it do you need help with?
- Problems you are experiencing?
I want it to display just one leaderstat named “Score” and the GUI object I want to use is a SurfaceGui. I just need help with making the script. I tried using this script and it didn’t work:
while true do
wait()
script.Parent.Text = "Score: "..game.Players.LocalPlayer.leaderstats.Score.Value
end
local billboardgui = --whereever you put the billboard gui
game.Players.LocalPlayer.leaderstats.Score.Changed:Connect(function()
billboardgui.TextLabel.Text = "Score: " .. game.Players.LocalPlayer.leaderstats.Score.Value
end)
billboardgui.TextLabel.Text = "Score: " .. game.Players.LocalPlayer.leaderstats.Score.Value
It didn’t work for me. Have you tested it?