Game script give weapons when the number players are in the game

The weird part of this when i was testing my game with 2 players when the game started i gives the player the amount of player that the game is in weapon twice or the amount of the players in game (Shown in the video)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Maps = ServerStorage:WaitForChild("Maps")
local Status = ReplicatedStorage:WaitForChild("Status")
local Intermission = 15 -- This is the time in the lobby
local GameTime = 180 --The game time till it ends
local WinnerReward = 20 --This reward is only rewarded to the winner of each match
game.Players.PlayerAdded:Connect(function(player)
local PlayerAmount = 2 --This indicates how many players are suppost to be for the game to begain
local Spectate = game.Workspace.Lobby.Barrier

while true do
	
	Status.Value = "Waiting for "..PlayerAmount.." players to start the game!"
	
	repeat wait() until game.Players.NumPlayers >= 2

	for i = Intermission,0,-1 do
		
		Status.Value = "Intermission: "..i.."!"
		if i == 0 then
			wait(2)
			Status.Value = "Choosing Map!"
			wait(1)
		end
		wait(1)
	end
		local plrs = {}
		
		for i, player in pairs(game.Players:GetPlayers()) do
			if player then
				table.insert(plrs,player) -- Add each player into plrs table
			end
		end
		
		wait(1)
		
		local AvailableMaps = Maps:GetChildren()
		
		local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]
		
		Status.Value = ChosenMap.Name.. " by "..ChosenMap.Creator.Value.." has been choosen"
		wait(3)
		
		local ClonedMap = ChosenMap:Clone()
		ClonedMap.Parent = workspace
		
		--Teleport player to the map
		
		local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
		
		if not SpawnPoints then
			print("Spawnpoints not found!")
		end
		
		local AvaliableSpawnPoints = SpawnPoints:GetChildren()
		
		for i, player in pairs(plrs) do
			if player then
				character = player.Character
				
				if character then
					-- Teleport them
					
					character:FindFirstChild("HumanoidRootPart").CFrame = AvaliableSpawnPoints[1].CFrame + Vector3.new(0, 10, 0)
					table.remove(AvaliableSpawnPoints,1)
					
					Spectate.CanCollide = false
					Spectate.Transparency = 1
					
					-- Give them a sword
					local equipped = game.ServerStorage.PlayerData[player.Name].Equipped
					
					if equipped.Value ~= "" then
						local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
						weapon.Parent = player.Backpack
					else
						local Sword = ServerStorage.Sword:Clone()
						Sword.Parent = player.Backpack
					end
					
					
					local GameTag = Instance.new("BoolValue")
					GameTag.Name = "GameTag"
					GameTag.Parent = player.Character
					
				else
					--There is no character
					if not player then
						table.remove(plrs,i)
					end
				end
			end
		end
		
		wait(1)
	
		for i = GameTime,0,-1 do
			
			for x, player in pairs(plrs) do
				if player then
					
					character = player.Character
					
					if not character then
						--Left the game
						table.remove(plrs,x)
					else
						if character:FindFirstChild("GameTag") then
							--They are still alive
							print(player.Name.." is still in the game!")
						else
							-- They are dead
							table.remove(plrs,x)
							print(player.Name.." has been eliminated!")
						end
					end
				else
					table.remove(plrs,x)
					print(player.Name.." has been eliminated!")
				end
			end
			
			Status.Value = "The game will be over in "..i.." seconds"
			
			if #plrs == 1 then
				-- Last person standing
				Status.Value = ""..plrs[1].Name.." has won the match and won " ..WinnerReward.." Gears"
				plrs[1].leaderstats.Gears.Value = plrs[1].leaderstats.Gears.Value + WinnerReward
				break
			elseif #plrs == 0 then 
				Status.Value = "Nobody won!"
				break
			elseif i == 0 then
				Status.Value = "Time up!"
				break
			end
			
			wait(1)
		end
		
		print("End of game")
		
		wait(1)
		for i, player in pairs(game.Players:GetPlayers()) do
			character = player.Character
			
			if not character then
				--Ignore them
			else
				if character:FindFirstChild("GameTag") then
					character.GameTag:Destroy()
				end
				
				for _, tool in pairs(player.Backpack:GetChildren()) do
					if tool:FindFirstChild("Price") then
						tool:Destroy()
					end
				end
				
				
				
				for _, tool in pairs(character:GetChildren()) do
					if tool:FindFirstChild("Price") then
						tool:Destroy()
					end
				end
			end
			
			player:LoadCharacter()
		end
		
		ClonedMap:Destroy()
			
			Spectate.CanCollide = true
			Spectate.Transparency = 0.55
	end
	end)

Help please

1 Like

@VirtuallyEndless I think its happening because you are looping it for the amount of players in the game so, if there are 5 players in the server, each player will get 5 tool.

This is the loop I’m talking about

for i, player in pairs(plrs) do
			if player then
				character = player.Character
				
				if character then
					-- Teleport them
					
					character:FindFirstChild("HumanoidRootPart").CFrame = AvaliableSpawnPoints[1].CFrame + Vector3.new(0, 10, 0)
					table.remove(AvaliableSpawnPoints,1)
					
					Spectate.CanCollide = false
					Spectate.Transparency = 1
					
					-- Give them a sword
					local equipped = game.ServerStorage.PlayerData[player.Name].Equipped
					
					if equipped.Value ~= "" then
						local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
						weapon.Parent = player.Backpack
					else
						local Sword = ServerStorage.Sword:Clone()
						Sword.Parent = player.Backpack
					end