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
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)
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