Help with text script

im trying to make a script that changes a text label to a players leaderstats value e.g if you had 1000 coins then my gui would say 1000 coins
here is my script:
image
any help is appreciated!

1 Like

You would write this:

local Player = game:GetService("Players").LocalPlayer

Player.leaderstats.Coins:GetPropertyChangedSignal("Value"):Connect(function()
     script.Parent.Text = Player.leaderstats.Coins.Value
end)

This code updates the textlabel to display how many coins the player has when the Coins value gets updated/changed eg the player receives 1000 Coins.

1 Like

I would recommend adding WaitForChild to that just to be safe.

its not working. sometimes it does sometimes it doesn’t.

script.Parent.Text = player.leaderstats.coins.Value..' coins'

Remove the PlayerAdded function and just leave what I wrote out. Make it look exactly like I displayed in the first comment.

i have done that. i just copy and pasted what you sent into the local script

local players = game:GetService('Players')
local localPlayer = players.LocalPlayer
local leaderstats = localPlayer:WaitForChild('leaderstats')
local coins = leaderstats:WaitForChild('Coins')

script.Parent.Text = coins.Value
coins:GetPropertyChangedSignal('Value'):Connect(function()
	script.Parent.Text = coins.Value
end)

Do you have any errors in the output?

it says Coins is not a valid member of Folder “Players.hellobeede.leaderstats” but it is i think it has not loaded yet

Remove hellobeede that should fix the error and make sure it just says: Player.leaderstats

This is why you use WaitForChild.

2 Likes

yeah i just tested your script and seems to have worked. thanks a bunch!!!

1 Like

It stills works without WaitForChild.

yes but it seems to have a 50/50% of working wait for child seems to work best

It won’t. Instances won’t load uniformly and not always right away. You should always be using WaitForChild unless the script is a descendant of the target.

2 Likes

Sometimes only. Because sometimes the stats will load first, but other times the script runs before the stats get loaded.

I’m sorry, I just couldn’t help but laugh when I read that. He didn’t put hellobeede in his script, he hadPlayer.leaderstats, however since the stat wasn’t loaded in yet, an error was thrown in the output, the error pointed to where the error occurred, in this case Player was Players.hellobeede so it pointed to Players.hellobeeded.leaderstats

1 Like

i thought that to lol!!! i didnt think i was doing something wrong

1 Like