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

I need to remove tools from a players backpack using a script, Any help?

Asked by 7 years ago
Edited 7 years ago

I have been trying to remove tools using scripts for ages, Please may you help, These are all the codes I have tried.

In a local script, I did

game.Players.LocalPlayer.Backpack:Destroy()

Any other help?

I also tried

 for i,v in pairs(game.Players:GetChildren()) do --Get all children of players
    Backpack = v:FindFirstChild("Backpack",true)
    if Backpack ~= nil then  --Check if the child has a backpack
        c = Backpack:GetChildren() --Get the children of the backpack
        for i = 1,#c do
            c[i]:Destroy() --Use Destroy method instead
        end
    end
end)

But still didn't work

2
Backpack:ClearAllChildren() OldPalHappy 1477 — 7y
0
Try Print Debugging and :ClearAllChildren() abnotaddable 920 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

on join

local f = game.Players.LocalPlayer.BackPack:GetChildren()
for i = 1, #f do
if f[i].className == "Tool" then
f[i]:Remove()
end
end

or ontouch

function c(hit)
    hit.Parent:WaitForChild("Humanoid") --check if hit is a player
    local user = hit.Parent.Name
    local f = game.Players[user].Backpack:GetChildren()
    for i = 1, #f do
        if f[i].className=="Tool" then -- checks if its a tool
            f[i]:Remove()
        else
            print("item in backpack isnt a tool")
        end
    end
end
Ad
Log in to vote
0
Answered by
Kenley67 -12
7 years ago
-- Assuming local script
for i,v in pairs(game.Players.LocalPlayer.BackPack:GetChildren()) do
    if v:IsA("Tool") then
        v:Destroy()
    end
end)

Answer this question