Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How do I make a money GUI with the .Changed function script I have?

Asked by 7 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

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?

0
the script will be in Local Script Queen1234_XD -26 — 3y

2 answers

Log in to vote
0
Answered by
NexeusX 137
7 years ago

Local scripts are usually what you want to use in a Gui, especially withFiltering Enabled on.

Ad
Log in to vote
0
Answered by
awfulszn 394 Moderation Voter
7 years ago
Edited 7 years ago

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.

local Label = game.Players.LocalPlayer.PlayerGui.ScreenGui:FindFirstChild('TextLabel')
local Cash = game.Players.LocalPlayer.leaderstats:FindFirstChild('Points')

I am connecting to the event, .Changed, the function will run once the IntValue has changed.

Cash.Changed:Connect(function() 

Now because the IntValue was .Changed, the Label will update itself to whatever the Cash.Value is equal to.

Label.Text = '$'..tostring(Cash.Value)
end)

Full code;

local Label = game.Players.LocalPlayer.PlayerGui.ScreenGui:FindFirstChild('TextLabel')
local Cash = game.Players.LocalPlayer.leaderstats:FindFirstChild('Points')

Cash.Changed:Connect(function() 
Label.Text = '$'..tostring(Cash.Value)
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!

Answer this question