Hey, this script should equip a tool and it works, you can also unequip. But after the player have died, when you try to equip a tool again it clones 2 of the same tool. If you die another time it clones 3 tools of the the same tool and it keeps going like this. Does anyone know what could be the problem?
SS = game:GetService("ServerStorage")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
player:WaitForChild("ShopValues")
local gearValue = player.ShopValues:FindFirstChild("GearName")
local bp = player:FindFirstChild("Backpack")
local PG = SS:FindFirstChild("Gear"):GetChildren()
local PE = SS:FindFirstChild("Gear")
gearValue.Changed:Connect(function(val)
for i,v in pairs(PG) do
print("WhatTheCool?")
if gearValue.Value == "" and db == true then
db = false
if bp:FindFirstChild("GEAR") ~= nil then
bp.GEAR:Destroy()
end
elseif gearValue.Value == v.Name and db == true then
db = false
if bp:FindFirstChild("GEAR") ~= nil then
bp.GEAR:Destroy()
end
local clone = v:Clone()
clone.Name = "GEAR"
clone.Parent = player:FindFirstChild("Backpack")
end
end
end)
end)
end)
If you have any questions please ask me, thanks :) /Xsodar
