So, I'm writing code to remove items from a plays inventory but im getting a error from line one. The error is "Attempt to index nil with 'Backpack' " and I'm not sure why. From what I know, this code is fine but it clearly isn't. Thank you!
local gear = game.Players.LocalPlayer.Backpack:GetChildren()
local function onTouch(hit)
for i, child in ipairs(gear) do
child:Destroy()
print(game.Players.LocalPlayer.Name.." Inventory Cleared")
end
end
game.Workspace.Door.Touched:Connect(onTouch)

4 comments
Is the script a LocalScript?
No. Lol. Big brain time
Well, you can't use LocalPlayer in a ServerScript as it runs on the Server and not on the Client.
Now ive run into a nother error. When I touch the door, the inventory is not cleared. Any idea?