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

How to make this script only buy a tool once instead of multiple times?

player = script.Parent.Parent.Parent.Parent.Parent
money = player.leaderstats.Gold 
price = 100 
tool = game.Lighting:findFirstChild("Weapon Name Goes here")


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 comment

0

That'll require the use of DataStoreService.

1 answer

✓ Accepted answer
player = script.Parent.Parent.Parent.Parent.Parent
money = player.leaderstats.Gold 
price = 100 
tool = game.Lighting:findFirstChild("Weapon Name Goes here")
local co;

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

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

1 comment

0

thanks, i'm using it for a shopgui but after I close it and open it again I can still buy the tool though, could you please help me with that as well?

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