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

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

Asked by 1 year ago
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)
0
That'll require the use of DataStoreService. Ziffixture 6913 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your 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)

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? iJustLive 2 — 1y
Ad

Answer this question