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

How do I make a variable that adds up?

Asked by 4 years ago

I'm trying to make a 'Cash' variable that adds up over time. I don't think this is the right script, was a try though!

while true do
Cash = Cash + 5
Game.workspace.Part.SurfaceGUI.TextBox.Text = Cash
wait (20)
end
0
The script does add up the cash varaible. Do you mean changing the text of the SurfaceGUI? Erie20 102 — 4y
0
yea changing the text fundayelover 2 — 4y
0
hmm try game instead of Game or just removing the game completely as that is not needed Erie20 102 — 4y
0
... idk how that helps the SurfaceGUI work... fundayelover 2 — 4y
0
ik now its not textbox its textlabel. textboxes are for user input. textlabels are for display. Erie20 102 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

A simple error: there was a space in between the wait and the parameter. This can easily be fixed by doing:

local Cash = 0

while wait(20) do
    Cash = Cash + 5
    game.workspace.Part.SurfaceGUI.TextBox.Text = tostring(Cash)
end

I also recommend you use a TextLabel and not a TextBox

Edit: I realized that the value would be a number value so you must make it a string for it to work. I provided that in the code above

0
Notes: 1. Lua doesn't care about the space; 2. Lua (and often Roblox) automatically converts numbers to strings for things like Text; 3. It should be `game.Workspace` or just `workspace`; 4. The critical issue was `Cash` not existing (which you did fix with line 1). chess123mate 5873 — 4y
Ad

Answer this question