function CheckSword()
found = false
for i, v in pairs(Player.Backpack:GetChildren()) do
if v.Name == "Sword" then
found = true
end
if found == true then
return
end
end
end
Okay, so I'm trying to make it so that the player can only buy one sword, so if he or she has the sword in their backpack they will be denied. So this is the full script.
Player = game.Players.LocalPlayer
Price = 50
function CheckSword()
found = false
for i, v in pairs(Player.Backpack:GetChildren()) do
if v.Name == "Sword" then
found = true
end
if found == true then
return
end
end
end
script.Parent.MouseButton1Click:connect(function()
local leaderstats = Player:FindFirstChild("leaderstats")
if leaderstats ~= nil then
local Gold = leaderstats:FindFirstChild("Points")
if Gold ~= nil then
SwordFound = CheckSword()
if Gold.Value > Price and SwordFound == false then
Sword = game.Lighting.Sword:Clone()
Sword.Parent = game.Players[Player.Character.Name].Backpack
end
end
end
end)
But when I click "Buy", nothing happens. This started happening after I added the, for i, v in pairs part..
Any soloutions?
