Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Clear Inventory Before Given items?

I am making a loadout GUI and i cant figure out how to clear the inventory of the player.

The code stuff

Select.MouseButton1Click:Connect(function()
	if Value1.Value == true
	then
		M4A1.Parent = Player.Backpack
		G17.Parent = Player.Backpack
		AmmoBox.Parent = Player.Backpack
	end
end)

Value1 = the True/False Value in the Rifleman Button

The thing i want is that the inventory is cleared before the items are given.

1 answer

✓ Accepted answer

You can use a for i,v loop. Assuming that "Player" is the Player

for i,v in pairs(Player.Backpack:GetChildren()) do
v:Destroy()
end

for i,v in pairs(Player.Character:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end

You should use remote events to clear the player's inventory though

3 comments

0

What do you mean with a remote evnt

0

Without remote events the tools won't replicate to server, with means the only player that can see the tools is yourself, so you need to use remote events to make the tools replicate (https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events)

0

I have added the lines of code. and now i get this error: (The Parent property of G17 is locked, current parent: NULL, new parent Backpack)

This discussion is preserved as it was. New answers, comments, and votes are closed.