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

My shop gives me the Gravity Coil when i can afford it without me clicking buy

Asked by 10 years ago

Ok now it works but it buys it automatically when i have 250 points instead of me having to click first

player=Game.Players.LocalPlayer --This creates a variable for the player
Points=player:WaitForChild("leaderstats"):WaitForChild("Cash") --This makes a variable for their "Cash" value in leaderstats. If there isn't one, then this would cause an error. Giving us the output improves the likelyhood of us being able to give a good answer. I would replace this line with Points=player:WaitForChild("leaderstats"):WaitForChild("Cash")
upgradeStuff = game.Lighting.GravityCoil --This makes a vairable for the item being bought. Using ReplicatedStorage for storing things is better than Lighting tho.

function buy()--Creates a function to be called when the button's clicked.
if Points.Value >= 250 then --This checks if they have 250 points or more.

    Points.Value = Points.Value - 250 --This subtracts from their points

        upgradeStuff:clone().Parent = player.Backpack --This gives them the gravity coil

    wait(2)--Waits a bit, not quite sure why this is here.
else --If they don't have enough points
        script.Parent.Parent.Text = "You cant afford this!" --Tell them they can't afford it
    wait(3)--Wait a bit
        script.Parent.Parent.Text = "Gravity Coil"  --Return the text to normal
end--Idk how to explain "end" to you. Check wiki.roblox.com for that one.
end

script.Parent.MouseButton1Down:connect(buy())--Don't forge


Its in a Local Script

How do i make it so you have to click buy first and you dont get it as soon as you can afford it?!

1
No clue why it's not working properly, sorry trogyssy 221 — 10y
0
/\ Well then that comment was a complete waste of valuable time and energy. ConnorVIII 448 — 10y

1 answer

Log in to vote
5
Answered by
AxeOfMen 434 Moderation Voter
10 years ago

The answer is that you are invoking the buy function when you connect it to the MouseButton1Down event.

On line 20, instead of this:

script.Parent.MouseButton1Down:connect(buy())

do this:

script.Parent.MouseButton1Down:connect(buy)
1
Thanks so much it worked!!! U have a very keen eye! SirKitten2000 0 — 10y
0
Scrap AxeOfMen you could be called KeenEyeOfMen. ConnorVIII 448 — 10y
Ad

Answer this question