Script gives a tool for the number of players

This script is a server script and when ever I run it, it gives players the number of swords of players in game. I fixed it a bit but when I tested it, it gave 1 sword to one player then 2 to the other player. I’m not sure why its not working and I have tried a few things. Help would be very appreciated!

local function Sword1()
	local Players = game:GetService("Players")
	-- Tables
	local playerInRound = {}
	local connections = {}
	-- Main Script

	local children = workspace.Ingame:GetChildren()
	print("Worked")
	for _,  Player in pairs(Players:GetChildren()) do
		if Player.Character and Player.Character:FindFirstChild('Humanoid') then
			for i = 1,#children do
				print(i)
				local clone = map:FindFirstChild("Tool"):Clone()
				if Player.Character:FindFirstChild("Tool") then
				else
					clone.Parent = children[i]
				end
				table.insert(playerInRound, Player)
				connections[Player.name] = Player.Character.Humanoid.Died:Connect(function()
					table.remove(playerInRound, table.find(playerInRound, Player))
			end)
		end
	end
end

I don’t understand your script fully, what is workspace.Ingame? also on the line

clone.Parent = children[i]

why don’t you set the parent to Player.Character? why children[i]

1 Like

workspace.ingame is the folder for the players characters that are in the game so the mini game can tell how many people are in still. Then for your second question I didn’t think about it that way.

I swithced up that line you quoted and it worked :skull:! Thank you

1 Like