I have an inventory script that saves the items when a player leaves, and I have this script here that adds swords into the inventory, but it should detect if the sword is already in the inventory but it just duplicated the inventory everytime I join, any idea why?
local SS = game:GetService("ServerStorage")
local sword = SS.Sword
local darkheart = SS.Darkheart
local illumina = SS.Illumina
local darkheartKills = 10000
local illuminaKills = 20000
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(chr)
task.wait(0.5)
if plr:WaitForChild("Backpack"):FindFirstChild("Sword") then
print("Owned")
else
sword:Clone().Parent = plr:WaitForChild("Backpack")
end
local killsValue = plr.leaderstats.Kills
killsValue:GetPropertyChangedSignal("Value"):Connect(function()
if plr:WaitForChild("Backpack"):FindFirstChild("Darkheart") then
print("Owned")
else
if plr.Character:FindFirstChild("Darkheart") then
print("Owned")
else
if killsValue.Value >= 10000 then
darkheart:Clone().Parent = plr:WaitForChild("Backpack")
end
end
end
if plr:WaitForChild("Backpack"):FindFirstChild("Illumina") then
print("Owned")
else
if plr.Character:FindFirstChild("Illumina") then
print("Owned")
else
if killsValue.Value >= 20000 then
illumina:Clone().Parent = plr:WaitForChild("Backpack")
end
end
end
end)
end)
end)