Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[SOLVED]Clones more than 1 wep when a person has the same value?

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.

2 answers

✓ Accepted answer

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

2 comments

0

Thanks!

0

No problem.

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

1 comment

0

I appreciate this. Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.