Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

LocalScript doesn't work at all, Please help?

I've tried everything I can to make this LocalScript work, but it doesn't. Nothing shows up in the output.

local plr = game.Players.LocalPlayer
local amofcash = plr.leaderstats:WaitForChild('Cash').Value

script.Parent.Text = '$ '..plr.leaderstats:WaitForChild('Cash').Value
amofcash.Changed:connect(function()
script.Parent.Text = '$ '..plr.leaderstats:WaitForChild('Cash').Value
end)

2 comments

1

Please use your variubles. You have created them for a reason, right?

0

Please you don't know anything. Stop

2 answers

✓ Accepted answer

The changed event should be referencing the value object, not its value property. In other words, it should be Cash.Changed and not Cash.Value.Changed

Also, use variables if you've initialized them.

Basically, your script should be changed to this:

local plr = game.Players.LocalPlayer
local amofcash = plr.leaderstats:WaitForChild('Cash'

script.Parent.Text = '$ '.. amofcash.value
amofcash.Changed:connect(function()
script.Parent.Text = '$ '.. amofcash.Value
end)

Where is this LocalScript? It will only run if it's in the player's backpack, PlayerGui, PlayerScripts, the player's character model, or ReplicatedFirst.

3 comments

0

It's parent is the TextLabel that it's text should change when a player's cash is changed. Problem is it's always on $0 which is the default

1

Oh, gotcha. You didn't explain your issue very well so I assumed it was an issue with the script's code executing at all. Your issue with updating the values stems from how you fired the .Changed event. A value object's .Value property won't return the change needed for the event to fire, so changing the event to be fired when the Cash object of leaderstats is changed should fix your problem.

0

In other words, plr.leaderstats.Changed:connect(function() --your code here end)

This discussion is preserved as it was. New answers, comments, and votes are closed.