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

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

Asked by 9 years ago

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)
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 Bman8765 270 — 9y

2 answers

Log in to vote
2
Answered by 9 years ago

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

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. My_Comment 95 — 9y
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. My_Comment 95 — 9y
0
Fixed the 'compare number with string' part. DigitalVeer 1473 — 9y
0
What about removing 50 pickles from the current amount? My_Comment 95 — 9y
View all comments (4 more)
0
Added that. DigitalVeer 1473 — 9y
0
Thank you so much! You helped greatly! My_Comment 95 — 9y
0
No problem. Can you put my answer as 'Solved' please :) DigitalVeer 1473 — 9y
0
Sorry for waiting so long to accept your answer, I completely forgot! My_Comment 95 — 7y
Ad
Log in to vote
-2
Answered by
woodengop 1134 Moderation Voter
9 years ago
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.

0
You are missing an 'end' for the if-statement. DigitalVeer 1473 — 9y
0
You also forgot that I wanted to see if it was higher than 50. My_Comment 95 — 9y

Answer this question