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

Clearing inventory doesn't work?

Hello,

I have an GUI shop where you can buy stuff. So my question is. Example, I buy Gravity Coil then it stays until I leave from Game.

My question is, I've tried to make a code which will remove everything from Backpack when you've died 3 times.

if Player.leaderstats.Deaths.Value == 3 then
	Player.leaderstats.Deaths.Value = Player.leaderstats.Deaths.Value - 3
	Player.Backpack:ClearAllChildren()

Right now it only removes one item from Backpack, but if you respawn then it comes back. How can I fix that? Thanks!

1 answer

✓ Accepted answer

Why don't you use a In pairs loop to loop through all the tools in Backpack and Destroy() them?

	if Player.leaderstats.Deaths.Value == 3 then
   		for _,v in pairs(Player:WaitForChild("Backpack"):GetChildren()) do
				v:Destory()
		end
	end

~UserOnly16Charcters, Hoped I helped you to answer your question! If you have any further question, don't hesitate to comment below!!

Edited: This script delete the Weapons from the StarterGear

	if Player.leaderstats.Deaths.Value == 3 then
   		for _,v in pairs(Player:WaitForChild("StarterGear"):GetChildren()) do
				v:Destory()
		end
	end

4 comments

0

Hello, I got many "Items/Tools" how can I enter all there?

0

I edited the script so it should loop through all the Objects in Backpack and delete them all.

0

Sir, How to make it still delete items. Item's come from StarterGear as well, so if player dies before "3", he would keep items until he got 3 deaths. Thanks :)

0

Edited.

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