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

How can I stop players from buying a gear twice?

I tried several ways to stop this script from allowing you to buy the items more than once but nothing is working.

player = script.Parent.Parent.Parent.Parent.Parent
money = player.leaderstats.Credits
price = script.Parent.Price.Value
tool = game.ReplicatedStorage:findFirstChild("TG45")


function buy()
	
if money.Value >= price then
money.Value = money.Value - price
local a = tool:clone()
a.Parent = player.Backpack
player.GearStats.TG45.Value = true 
end
end
script.Parent.MouseButton1Down:connect(buy)

1 answer

check if the player already has the tool in their backpack

player = script.Parent.Parent.Parent.Parent.Parent
money = player.leaderstats.Credits
price = script.Parent.Price.Value
tool = game.ReplicatedStorage:findFirstChild("TG45")


function buy()

if money.Value >= price then
if player.Backpack:FindFirstChild(tool) == nil then
if money.Value >= price then
money.Value = money.Value - price
local a = tool:clone()
a.Parent = player.Backpack
player.GearStats.TG45.Value = true 
end
end
end
script.Parent.MouseButton1Down:connect(buy)

2 comments

0

The script dosen't work when I try this

0

whats the error?

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