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

How do I check if a textbox says "50 Pickles" or more?

I want to make upgrades for my game, but at an expense to a user. When this button is clicked, it is supposed to check if the user has 50 or more pickles. If the user DOES have 50 or more, then it would take 50 pickles away and ad 1 to PPS.

Pickles = script.Parent.Parent.Pickles
PPS = script.Parent.Parent.Parent.PPS
P = 0

script.Parent.MouseButton1Click:connect(function()
	if Pickles.Text == 50 .. " Pickles" then
    P = P + 1
    PPS.Text = P .. " Pickles Per Second"
end)

1 comment

0

You could make a string pattern and separate the spaces but it would be a lot easier to just store the amount of Pickles the user has in an IntValue

2 answers

✓ Accepted answer

Try using string patterns:

sp = script.Parent;
Pickles = sp.Parent.Pickles;
PPS = sp.Parent.Parent.PPS;
P = 0;

script.Parent.MouseButton1Click:connect(function()
local str = Pickles.Text;
local numOfPickles = tonumber(str:match("^%d+"));
if numOfPickles >= 50 then
Pickles.Text = (numOfPickles - 50) .. " Pickles";
P = P + 1;
PPS.Text = P.." Pickles Per Second";
end
end)

You can find more on String Patterns at this link:

http://wiki.roblox.com/index.php?title=String_pattern

8 comments

0

Thank you! This was very helpful, but you forgot about the part where it removed 50 pickles from the current amount of pickles, and I dont have a clue on how to do this.

0

And also, I added another "Parent" to Pickles to access the right frame, but something is wrong with line 9. "if numOfPickles >= 50 then" That you cannot compare a number with a string.

0

Fixed the 'compare number with string' part.

0

What about removing 50 pickles from the current amount?

0

Added that.

0

Thank you so much! You helped greatly!

0

No problem. Can you put my answer as 'Solved' please :)

0

Sorry for waiting so long to accept your answer, I completely forgot!

Pickles = script.Parent.Parent.Pickles
PPS = script.Parent.Parent.Parent.PPS
P = 0

script.Parent.MouseButton1Click:connect(function()
    if Pickles.Text =="50 Pickles" then -- Should be
    P = P + 1
    PPS.Text = P .. " Pickles Per Second"
end
end)

I don't see any other errors.

2 comments

0

You are missing an 'end' for the if-statement.

0

You also forgot that I wanted to see if it was higher than 50.

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