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

How do I make this work?

Asked by
FizTech 15
8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

~ 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.

1 answer

Log in to vote
0
Answered by 8 years ago

Suggestions


  • Events
    • Firstly, I'd just like to point out creating an 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.

0
The upgrade button works. I just want the upgrade to be become more expensive and have more value every time I click the upgrade button. FizTech 15 — 8y
0
Updated the answer. ScriptGuider 5640 — 8y
0
You wouldn't want to use a single button -- it would make it so that you wouldn't be able to continue buying the upgrade. As it now stands, each time you click the button you lose 10 gold and gain 1. You'll want to use two buttons. Perci1 4988 — 8y
0
Ok FizTech 15 — 8y
Ad

Answer this question