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

Clearing inventory doesn't work?

Asked by 9 years ago

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

Log in to vote
0
Answered by 9 years ago

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

0
Hello, I got many "Items/Tools" how can I enter all there? Maamees13 5 — 9y
0
I edited the script so it should loop through all the Objects in Backpack and delete them all. UserOnly20Characters 890 — 9y
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 :) Maamees13 5 — 9y
0
Edited. UserOnly20Characters 890 — 9y
Ad

Answer this question