I'm making a clicker game, and I don't know how to make this shop function work. Basically, there is a textbutton that gives you a boost for each click, but you have to have 100 clicks for it. It does detect the 100 clicks, BUT, then I can press it over and over again, even if I am under 100 clicks. Can anyone help? Here's my current script:
local player = game.Players.LocalPlayer
local clicks = player.leaderstats.Clicks
function shop()
script.Parent.Activated:Connect(function()
if script.Parent.Activated then
script.Parent.Activated:Connect(function()
clicks.Value = clicks.Value - 100
script.Parent.Parent.click.Activated:Connect(function()
clicks.Value = clicks.Value + 1
end) end) end end) end
while true do
wait()
if clicks.Value >= 100 then break
end
shop()
end
BTW: I am not asking for a whole new script, I just need to be guided in the right direction. Thank you!

21 comments
what do you mean by " BUT, then I can press it over and over again, even if I am under 100 clicks. "
You are only supposed to be able to buy the upgrade if you have equal to or over 100 clicks.
But, you can keep buying it. Even if under 100 clicks.
Ohh, you need an if statement that checks if they have 100 clicks or more then
I have that in the script. Still dosen't work.
can you post a gif or something? im a bit confused what you're trying to do
Alright.
also why do you have this twice?
script.Parent.Activated:Connect(function() if script.Parent.Activated then script.Parent.Activated:Connect(function()
That's just how it works... And I can't post a gif. I'll explain in as much depth as I can. So. I am clicking. I get past 100. I can upgrade, but I try to spam click. Then my clicks go into negatives, because the upgrade is still processing. The loop doesn't detect if the clicks are under 100 anymore.
Well, the reason is because once you break the loop, it's done
Well, thats the problem, I don't wanna keep putting the same loop over and over again.
https://gyazo.com/355b4cd8b9f3777f509384f4118c17ef
something like that is what you're trying to do?
if so, the script is in answers
That is not it.
It's supposed to remove 100 clicks AND add 1 click to each click.
you need another value then, named Power or something, increase it by 1 when it reaches 100
Wdym..?
so you mean you want to click 100 times and make it when you click after that, to do 2 clicks at once instead of 1.?
i edited the code so you can kinda see what i mean