How would I delete a players inventory

I’m trying to delete a players inventory if they’re on a specific team, once the round is over I want to return the players inventory and ability to pick up items. How would I be able to do this

local team = game:GetService("Teams").Ape
local character = plr.Character


if plr.Team == team then
	local backpck = plr:WaitForChild("Backpack")
	backpck:Destroy()
		
	end

Heres what I have but currently doesnt work

The backpack is part of CoreGUI, allowing you to disable and enable it at your will while still keeping your items.

Example (LocalScript):

local team = game:GetService("Teams").Ape
local character = plr.Character


if plr.Team == team then
	game:GetService('StarterGui'):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
end

To enable the inventory again, just simply replace false with true:

game:GetService('StarterGui'):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)

Hope this helped,
Fizzitix

2 Likes

The team name is Ape

The problem is that you are trying to delete the child before it has been created. The only way to fix this is to wait for the child to be created, or if you want to do it in a more efficient way, you will have to do it in the character added event.
local team = game:GetService(“Teams”).Ape

game.Players.PlayerAdded:Connect(function(plr)
if plr.Team == team then
local character = plr.Character
character.ChildAdded:Connect(function(child)
if child.Name == “Backpack” then
child:Destroy()
end
end)
end
end)