I have this script:
Cash.Changed:connect(function() Label.Text = '$'..tostring(Cash.Value) end)
Should I put this in a local script or just a script?
Is there anything I need to add to the script to make the money GUI work?
Local scripts are usually what you want to use in a Gui
, especially withFiltering Enabled
on.
Assuming this is your hierarchy, then here is the following code;
I have set up two variables
to define the location of both the TextLabel, and the Points.
1 | local Label = game.Players.LocalPlayer.PlayerGui.ScreenGui:FindFirstChild( 'TextLabel' ) |
2 | local Cash = game.Players.LocalPlayer.leaderstats:FindFirstChild( 'Points' ) |
I am connecting to the event, .Changed
, the function will run once the IntValue has changed.
1 | Cash.Changed:Connect( function () |
Now because the IntValue
was .Changed
, the Label will update itself to whatever the Cash.Value
is equal to.
1 | Label.Text = '$' .. tostring (Cash.Value) |
2 | end ) |
Full code;
1 | local Label = game.Players.LocalPlayer.PlayerGui.ScreenGui:FindFirstChild( 'TextLabel' ) |
2 | local Cash = game.Players.LocalPlayer.leaderstats:FindFirstChild( 'Points' ) |
3 |
4 | Cash.Changed:Connect( function () |
5 | Label.Text = '$' .. tostring (Cash.Value) |
6 | end ) |
This code should be in a localscript
.
Also, It has been pointed out to me that instead of :connect
, you should be using :Connect
as it has since been deprecated. The same thing with the signal events, disconnect
and wait
.
Hope this helps! Don't forget to accept my answer if this works for you, or leave a comment if you need further assistance!