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

How do I make this script to only buy a tool once and not multiple times?

Asked by 2 years ago
player = script.Parent.Parent.Parent.Parent.Parent
money = player.leaderstats.Cash 
price = 5 
tool = game.Lighting:findFirstChild("Tool")


function buy()
    if money.Value >= price then
        money.Value = money.Value - price
        local a = tool:clone()
        a.Parent = player.Backpack
        local b = tool:clone()
        b.Parent = player.StarterGear

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

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

What you need to do before running this script: 1. Make a bool value inside the script called AlreadyPurchased 2. Use the script below

Script:

player = -- Path to player here --
money = player.leaderstats.Cash 
price = 5 
tool = -- Path to tool --
local Value = script.AlreadyPurchased


function buy()
   if script.AlreadyPurchased == true then
   return
   else
    if money.Value >= price then
        money.Value = money.Value - price
        local a = tool:clone()
        a.Parent = player.Backpack
        local b = tool:clone()
        b.Parent = player.StarterGear

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

Also if you like you can add a datastore so it saves. Hope this helps!

0
I inserted in the paths from the other script and also added the bool value inside the script but it doesn't seem to work for me :( iJustLive 2 — 2y
0
Oh! I am sorry about that, I will try to get a new script that might work. cool1234great 3 — 2y
Ad

Answer this question