Game removes all gears except for the gear the player is holding

Issue
Hello! I made a script that adds and removes gears at the start/end of the round. From testing, I have found that the script does remove the gear in the player’s backpack but not the gear the player is holding. I have sourced the internet but haven’t found a solution.

Code
This part of the script removes the gears from the player’s backpack other than the one the player is using:

inRound.Changed:Connect(function()

				if inRound.Value == false then

					for i, plr in pairs(game.Players:GetPlayers()) do

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

						humanRoot.CFrame = game.Workspace.lobbySpawn.CFrame

					end	
				end	
			end)

Credit to mari230899 for the help on this script.

This script adds the gears, though I dont think you need to worry about this one.

game.Workspace.ChildAdded:Connect(function(child)
	if child.Name == "Sword Fights on the Heights IV" then
		
		
		local musicFolder = game.SoundService.Music

		for _, v in pairs(musicFolder:GetChildren()) do
			v:Stop() --stops all playing music
		end
		game.SoundService.Music.SFOTHTheme:Play()
		
		for index, plr in pairs(game.Players:GetPlayers()) do
			if plr:FindFirstChild("Backpack") then
				-- Adds gear right here! (hey that rhymes :O)
				local tool = game.ServerStorage.Tools.ClassicSword:Clone()
				tool.Parent = plr.Backpack
			end
		end

		local function skyChange()
			SFOTHSky.Parent = Lighting
			DefaultSky.Parent = Skyboxes
		end

		skyChange()
	end
end)

Thanks for any help!

2 Likes

then remove the Gear the Player is Holding

local Tool = Player.Character:FindFirstChildOfClass("Tool")
-- Find Object Based on Class (Which in this Case: A Tool)

if Tool then -- If Tool was found
   Tool:Destroy() -- Destroys Tool
end
2 Likes
inRound.Changed:Connect(function()

				if inRound.Value == false then

					for i, plr in pairs(game.Players:GetPlayers()) do

						local char = plr.Character
						local humanRoot = char:WaitForChild("HumanoidRootPart")
						plr.Backpack:ClearAllChildren()
char:FindFirstChildOfClass("Tool"):Destroy()


						humanRoot.CFrame = game.Workspace.lobbySpawn.CFrame

					end	
				end	
			end)
2 Likes

I know they already gave the answer, but just to explain, when the player is holding a tool, it leaves his Inventory (player.Backpack) and goes to his body (player.Character)

1 Like

Ah, thank you for the explanation. I was not sure if it was an actual bug in my code or just an extra line I needed to add.

1 Like

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