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)
COMMUNITY QUESTION
How do I make this script to only buy a tool once and not multiple times?
1 answer
What you need to do before running this script:
- Make a bool value inside the script called AlreadyPurchased
- 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!
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
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 :(
Oh! I am sorry about that, I will try to get a new script that might work.