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