Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Tool remover problem, wont remove equipped items?

I have a tool remover for the block so that whenever u touch the block, it removes all ur items from ur backpack. Problem is, that it only removes tools that u dont have equipped. If u have a weapon equipped, it wont remove it unless u unequip it. here is the script:

function hit(part)
	if hit == nil then return end
	h = game.Players:GetPlayerFromCharacter(part.Parent)
	if h ~= nil then
		c = h.Backpack:GetChildren()
		for i=1,#c do
			c[i]:remove()
		end
	end
end

script.Parent.Touched:connect(hit)

pls help i need an answer

2 answers

you can simply use ClearAllChildren()

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local checks = hit.Parent:GetChildren()
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		for i,v in pairs(checks) do
			if v:IsA("Tool") then
				v:Destroy()
			end
		end
		player.Backpack:ClearAllChildren()
	end
end)

4 comments

0

nope, doesn't work...

0

maybe make a touch script where it checks if an item is equipped then it removes the item u have equipped?

0

oh my bad, i didn't read your question fully. Now it should work.

0

you literally just did what I did

3 ways you can do this:

1: Cycle through the player to see if any tools are equipped (not recommended)

2: Use Humanoid:UnequipTools (Ok way)

3: Remove the tool from the character directly (I like this way)

For number 1, use a for loop:

for i,v in pairs (character:GetChildren()) do
	if v:isA("Tool") then --checks if it is a tool :P
		v.Parent = player.Backpack
	end
end

For number 2, use one line of code

Humanoid:UnequipTools()

For number 3, do the same as number one but replace the “v.Parent” part with a delete or whatever

5 comments

0

After one and two, just remove tools from players backpack

0

used method 2, didnt work, this was wat i did script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then hit.UnequipTools() end end)

0

It’s hit.Parent.Humanoid:UnequipTools() you’re saying unequip tools to an object, with a colon

0

still doesnt work, hopefully im doing everything correctly... here: for i,v in pairs (character:GetChildren()) do if v:isA("Tool") then --checks if it is a tool :P v.Parent = player.Backpack end end

0

wait no sorry this one: script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then for i,v in pairs (character:GetChildren()) do if v:isA("Tool") then --checks if it is a tool :P hit.Parent.Humanoid:UnequipTools() end end end end)

This discussion is preserved as it was. New answers, comments, and votes are closed.