Removing tools from backpack

Currently I have this round system which gives the player a Sword once the round starts. How would I go about removing/destroying the sword from the players’ backpack once the round ends and the players are teleported back to the lobby?

inRound.Changed:Connect(function ()
	
	if inRound.Value == true then
		
		for i, plr in pairs(game.Players:GetChildren()) do
			
			local char = plr.Character
			local humanRoot = char:WaitForChild("HumanoidRootPart")
			
			local CloneBasic = BasicSword:Clone()
			CloneBasic.Parent = plr.Backpack
			
			
			-- humanRoot.CFrame = game.Workspace.mapSpawn.CFrame
			
			local spawns = firstMap:FindFirstChild("Spawns")
			local points = spawns:GetChildren()
			
			plr.Character:WaitForChild("HumanoidRootPart").CFrame = points[i].CFrame --This
			
			table.remove(points,1)
			
			plr.Team = playingTeam
			
			char:WaitForChild("Humanoid").Died:Connect(function()
				
				plr.Team = lobbyTeam
				
				
			end)

			
		end
		
	else
		
		for i, plr in pairs(game.Players:GetChildren()) do

			local char = plr.Character
			local humanRoot = char:WaitForChild("HumanoidRootPart")


			humanRoot.CFrame = game.Workspace.lobbySpawn.CFrame
			
			plr.Team = lobbyTeam
			
		end
	end 
end)

Just :Destroy the tools. Your code also has quite a few other vulnerabilities like not accounting for if the player doesn’t have the HumanoidRootPart or if the character doesn’t exist. You might want to fix those after.

Code:

inRound.Changed:Connect(function()
	if inRound.Value then
		for i, plr in game.Players:GetPlayers() do
			local char = plr.Character
			local humanRoot = char:WaitForChild("HumanoidRootPart")

			local CloneBasic = BasicSword:Clone()
			CloneBasic.Parent = plr.Backpack


			-- humanRoot.CFrame = game.Workspace.mapSpawn.CFrame

			local spawns = firstMap:FindFirstChild("Spawns")
			local points = spawns:GetChildren()

			plr.Character:WaitForChild("HumanoidRootPart").CFrame = points[i].CFrame --This
			
			table.remove(points,1)

			plr.Team = playingTeam

			char:WaitForChild("Humanoid").Died:Connect(function()
				plr.Team = lobbyTeam
			end)
		end
	else
		for i, plr in game.Players:GetPlayers() do
			if plr.Team == lobbyTeam then
				continue
			end
			
			plr.Team = lobbyTeam
			plr.Backpack:ClearAllChildren()

			local char = plr.Character
			local humanRoot = char and char:FindFirstChild("HumanoidRootPart")
			
			for i, child in ipairs(char:GetChildren()) do
				if child:IsA("Tool") then
					child:Destroy()
				end
			end
						
			if humanRoot then
				humanRoot.CFrame = workspace.lobbySpawn.CFrame
			end
		end
	end 
end)
1 Like

Thanks a lot! I’ll also look into the things that you suggested.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.