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

How do I make a variable that adds up?

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

5 comments

0

The script does add up the cash varaible. Do you mean changing the text of the SurfaceGUI?

0

yea changing the text

0

hmm try game instead of Game or just removing the game completely as that is not needed

0

... idk how that helps the SurfaceGUI work...

0

ik now its not textbox its textlabel. textboxes are for user input. textlabels are for display.

1 answer

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

1 comment

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).

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