for i, plr in ipairs(game.Players:GetChildren()) do if plr.leaderstats.value.Value == 1 then for i, player in pairs(game.Players:GetChildren()) do if player:FindFirstChild("Backpack") then SS.SWeps.Sword:clone().Parent = player:FindFirstChild("Backpack") end end end end
When 2 or more people have the same leaderboard value, it clones 2 or more swords depending on how many people have the same value.
EX: When 3 people have the same leaderboard value it clones 3 swords into the peoples backpack instead of 1.
You don't need the second for loop; that is what is getting you the multiple swords. The second if statement also may slow it down a little bit, and is unneeded.
for i, plr in ipairs(game.Players:GetPlayers()) do if plr.leaderstats.value.Value == 1 then SS.SWeps.Sword:clone().Parent = plr:WaitForChild("Backpack") end end
Try this code:
for i,Player in pairs(game.Players:GetChildren()) do if Player.leaderstats.value.Value==1 then if Player:FindFirstChild("Backpack") then SS.SWeps.Sword:Clone().Parent=Player:FindFirstChild("Backpack") end end end
Explanation: You were using two 'for' loops, meaning for every player, you'd loop through each player and add a tool to their backpack
I removed the second 'for' loop so that it only gives the player a sword if their Value is equal to 1