Remove tool from ALL players when teleported back to lobby?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    When they teleport back to the lobby, the sword in their inventory must be removed.
  2. What is the issue?
    I have tried multiple methods and none will work, I can’t remove the swords from the players.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? (yes)
    I’ve tried looping through the playerlist, didn’t work, I’ve tried removing it when they touch a part in
    the lobby, that removed it, but made it so that they couldn’t get it back after.
while true do
	wait(1)
	
	if gameMode == 1 then -- Intermission 
		-- set the intermissionTime to the intTimerlabel text ON BOTH LABELS
		interTimerLabel.Text = tostring(intermissionTime)
		interTimerLabel2.Text = tostring(intermissionTime)
		
		-- decrement intermissionTime
		intermissionTime = intermissionTime - 1
		
		-- if it hits 0, set it back to 30, switch gamemode, and teleport players
		if intermissionTime < 1 then
			-- change the current gameMode to round in progress (2)
			gameMode = 2
			
			intermissionTime = 31
			
			-- Give all the players in the game swords
			for _,player in ipairs(game.Players:getChildren()) do
				local tool = game.ReplicatedStorage.ClassicSword:Clone()
				tool.Parent = player.Backpack
			end
			
			-- teleport all the players to the arena
			target = CFrame.new(14, 1.715, 62.3) --could be near a brick or in a new area
			for i, player in ipairs(game.Players:GetChildren()) do
				--Make sure the character exists and its HumanoidRootPart exists
				if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
					--add an offset of 5 for each character
					player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)
				end
			end
		end
		
	elseif gameMode == 2 then -- Match in progress
		-- set the arenaTimer text to matchTime
		arenaTimerLabel.Text = tostring(matchTime)
		
		-- decrement matchTime by 1
		matchTime = matchTime - 1
		
		-- if matchTime gets to 0, set it back to 180, switch gamemode, and teleport players
		if matchTime < 1 then
			-- change gamemode to intermission
			gameMode = 1
			
			intermissionTime = 31
			matchTime = 181
			
			-- sword is removed when the player touches the lobby floor
			
			-- teleport all the players to the LOBBY
			target = CFrame.new(24.5, 57.305, 50.4) --could be near a brick or in a new area
			for i, player in ipairs(game.Players:GetChildren()) do
				--Make sure the character exists and its HumanoidRootPart exists
				if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
					--add an offset of 5 for each character
					player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)
				end
			end
		end
	end
end
1 Like

you would just use a for i,v in pairs loop and use 2 conditions to remove the tool:

for i,v in pairs (game.Players:GetChildren()) do
if v:FindFirstChild("ClassicSword") then
v:FindFirstChild("ClassicSword"):Destroy()
elseif v.Character:FindFirstChild("ClassicSword") then
v.Character:FindFirstChild("ClassicSword"):Destroy()
else
print("player doesnt have sword")
end
end

@Ender_BX is on the right track with using for loops. Now if you want to remove all the tools and not just one you could do the following in a script,

for _, player in pairs(game.Players:GetPlayers()) do -- use :GetPlayers as it loops through players
    for i, tool in pairs(player:WaitForChild("Backpack"):GetChildren()) do -- loop through the players backpacks as they house the tools
        tool:Destroy() -- destroy every tool
    end
end

So wherever you have your function to teleport the players back to the lobby insert this chunk of code there.

1 Like