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

How to go through a specific players Backpack?

Asked by 7 years ago

Problem: I have created a tool that will remove all the scripts in the player's model and the player's Backpack. The problem is I can remove the scripts in the player's model but not in the player's Backpack. What I thought the best way to do this would be to create a variable ( as seen below) to check the mouse.Target.Parent and then do a for loop after getting the players do check if the name matches a name in the players. Then to do another for loop to get into their Backpack and delete everything in there. The error I get is the :WaitForChild() is a nil value. Any help on if I am doing something wrong/just something simple I am overlooking?

--Here is a snippet of the code

local char = game.Workspace:WaitForChild("yougottols1")
local hum = char:WaitForChild("Humanoid")
local mouse = game.Players.LocalPlayer:GetMouse()
local tool8 = Instance.new("Tool")
tool8.Name = "RemoveScripts"
tool8.RequiresHandle = false
tool8.CanBeDropped = false
tool8.Parent = game.Players:WaitForChild("yougottols1").Backpack
local script8 = Instance.new("LocalScript")
script8.Parent = tool8


script8.Parent.Equipped:connect(function(equip)
    equip.Button1Down:connect(function(click)
        local target2 = mouse.Target.Parent
        print(target2.Name)
        if target2.Name ~= "Workspace" then
            print(target2.Name)
            for i,v in pairs(target2:GetChildren()) do
                if v:IsA("LocalScript") or v:IsA("Script") or v:IsA("Tool") or v:IsA("HopperBin") or v:IsA("Model") then
                    v:Destroy()
                end
            end
            print("We are here")
        for i,v in pairs(game.Players:GetPlayers()) do
            print("Got the players")
            if v.Name == target2.Name then
            print("FoundPlayers")
        for i,b in pairs(v.Name:WaitForChild("Backpack"):GetChildren()) do
            print("Second for")
            b:Destroy()
            print("Destroyed")
        end
    end
end
        end
     end)
end)

Any help would be greatly appreciated and if none of you understand the problem you can make the comment and I can clarify more. Thanks!

0
Is it a localscript, module script, or a serverscript? UnreadyHappiness 35 — 7y

1 answer

Log in to vote
1
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago

You loop over v.Name:WaitForChild("BackPack"):GetChildren(). It should be without the Name as you already have the Player object.

0
Oh, thanks. Didn't see that lol. yougottols1 420 — 7y
Ad

Answer this question