Here's what I got:
game.Players.PlayerAdded:connect(function(plr) local stats = Instance.new('IntValue', plr) stats.Name = 'leaderstats' local cash = Instance.new('IntValue', stats) cash.Name = 'Cash' cash.Value = 0 local c = game.StarterGui.Leaderboard.Frame.TextLabel wait() c.Text = "Cash: "..cash.Value end)
Ok, so what you basically want is a GUI, with a TextLabel
saying how much Cash the LocalPlayer
has.
First off, you want to make the GUI and theTextLabel
before any code. Once you have that, you add in a LocalScript
to the GUI. Your hierarchy should look like this:
StarterGui ScreenGui LocalScript TextLabel
Now once you have that, you want to open up your LocalScript
and start your script off by adding in the LocalPlayer
and the TextLabel
as a local variable.
local player = game.Players.LocalPlayer local textlabel = script.Parent:WaitForChild("TextLabel")
Now that you have made sure that you have go both of the key things, you want to add a while true do
loop, so the script is constantly looping, and that way when the players cash.Value
changes, so will the text.
while wait() do end
Now we add in the code inside the loop:
while wait() do textlabel.Text = player:WaitForChild("leaderstats"):WaitForChild("Cash").Value end
And now this is what he final script should look:
local player = game.Players.LocalPlayer local textlabel = script.Parent:WaitForChild("TextLabel") while wait() do textlabel.Text = player:WaitForChild("leaderstats"):WaitForChild("Cash").Value end
I hope this helped and be sure to +1 and accept the answer.
It it doesn't, please be sure to reply with any errors found in the output and I will go back and fix it.
If you want only the player to see their own cash. Make this a local script in the text label and remove the local c = game.StarterGui...etc. This is a local script in leaderboard.Frame.TextLabel
wait(); while wait(0.1) do script.Parent.Text = "Cash: "..game.Players.LocalPlayer.leaderstats.Cash.Value; end;