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

How do you add 1 to an existing number in a textbox?

Asked by 9 years ago

I am making a click to earn game, like make it rain. I have a textbox that starts out as "0 Pickles", and when they click the imagebutton, (a pickle) it increases the number in the textbox by one. Here is some code I tried below.

Pickles = script.Parent.Parent.Pickles

function onClick()
Pickles.Text = " +1 Pickles"
end

script.Parent.MouseButton1Click:connect(onClick)

1 answer

Log in to vote
1
Answered by 9 years ago

You need to have an independent value for the function to refer to.

Try something like this :

Pickles = script.Parent.Parent.Pickles
N = 0

script.Parent.MouseButton1Click:connect(function()
    N = N + 1
    Pickles.Text = N .. " Pickles"
end)

-- N works as a counter each time you click

I hope this helped!

TheArmoredReaper

0
Thank you! (P.S you forgot the ) after end :) My_Comment 95 — 9y
0
I need something that makes the "Pickles Per Second" count go up one, but it will take away 50 pickles. My_Comment 95 — 9y
0
do you mean When it reaches 50 it will subtract 50? woodengop 1134 — 9y
0
Like an upgrade to the PpS? TheArmoredReaper 173 — 9y
0
Yes, an upgrade, I made a new question, its almost solved, but if you could help the answer that almost worked that would help! My_Comment 95 — 9y
Ad

Answer this question