Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?!

2 comments

1

No clue why it's not working properly, sorry

0

/\ Well then that comment was a complete waste of valuable time and energy.

1 answer

✓ Accepted answer

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)

2 comments

1

Thanks so much it worked!!! U have a very keen eye!

0

Scrap AxeOfMen you could be called KeenEyeOfMen.

This discussion is preserved as it was. New answers, comments, and votes are closed.