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

How can I stop players from buying a gear twice?

Asked by 4 years ago

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

Log in to vote
0
Answered by
0msh 333 Moderation Voter
4 years ago

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)
0
The script dosen't work when I try this Michael_TheCreator 166 — 4y
0
whats the error? 0msh 333 — 4y
Ad

Answer this question