Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Tool remover problem, wont remove equipped items?

Asked by 4 years ago

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

Log in to vote
0
Answered by
0msh 333 Moderation Voter
4 years ago
Edited 4 years ago

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)
0
nope, doesn't work... ImprinintInc 18 — 4y
0
maybe make a touch script where it checks if an item is equipped then it removes the item u have equipped? ImprinintInc 18 — 4y
0
oh my bad, i didn't read your question fully. Now it should work. 0msh 333 — 4y
0
you literally just did what I did MmadProgrammer 35 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

0
After one and two, just remove tools from players backpack MmadProgrammer 35 — 4y
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) ImprinintInc 18 — 4y
0
It’s hit.Parent.Humanoid:UnequipTools() you’re saying unequip tools to an object, with a colon MmadProgrammer 35 — 4y
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 ImprinintInc 18 — 4y
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) ImprinintInc 18 — 4y

Answer this question