~ I'm still new at scripting and I still don't know much. What I'm trying to accomplish is every time I click a button I would get 10 gold. The upgrade button cost 10 gold and if I buy it i get more gold per taps. How do I make it so every time I click the upgrade button, the price of the upgrade will increase as well as the amount of gold per taps. For example: Upgrade - 10 gold, 2 gold per taps Upgrade - 15 gold, 3 gold per taps Upgrade - 20 gold, 4 gold per taps ect ect
Here is my code so far:
local button = script.Parent local player = game.Players.LocalPlayer local gold = player:WaitForChild("leaderstats").Gold local cost = 10 local boost = 1 local tap = player.PlayerGui:WaitForChild("Main").MainFrame.NOOB button.MouseButton1Click:connect(function() if gold.Value >= cost then gold.Value = gold.Value - 10 tap.MouseButton1Down:connect(function() gold.Value = gold.Value + boost end) end end)
Thanks.
event
on the same object every time you click the button
object, is a bad idea. If you're going to be working with the same objects, you should only have to connect to a certain event one time (unless of course you'll be disconnecting it at some other point in time).The solution?
Well, the solution is actually quite simple. Let's just remove that MouseButton1Down
event you have inside the button event, but keep the code in the body of it's function.
Now because you also want to increase the cost of the item each time, we would simply just increase the value of "cost" each successful purchase. Here's an example:
button.MouseButton1Click:connect(function() -- Also note we shouldn't want that other event in here, since it would connect a new event every time you made a purchase. if gold.Value >= cost then gold.Value = gold.Value - 10 gold.Value = gold.Value + boost cost = cost + 5 -- Increase the cost amount by 5 each purchase end end)
Hope that helped. If you have any questions, just let me know.