This script will listen for when a player is added to the game, and when their character is added. It then listens for when the character's humanoid dies and calls the 'deleteInventoryItems' function to delete all items in the player's backpack.

-- Place this script inside a LocalScript in StarterPlayerScripts

-- Function to delete all items in the player's inventory
local function deleteInventoryItems(player)
    -- Get the player's character
    local character = player.Character
    if not character then
        return
    end

    -- Find the player's backpack
    local backpack = character:FindFirstChild('Backpack')
    if not backpack then
        return
    end

    -- Delete all items in the backpack
    for _, item in ipairs(backpack:GetChildren()) do
        item:Destroy()
    end
end

-- Listen for player added event
game.Players.PlayerAdded:Connect(function(player)
    -- Listen for character added event
    player.CharacterAdded:Connect(function(character)
        -- Listen for humanoid died event
        character.Humanoid.Died:Connect(function()
            -- Call the function to delete inventory items
            deleteInventoryItems(player)
        end)
    end)
end)
Roblox Script: Delete Inventory Items On Death

原文地址: https://www.cveoy.top/t/topic/n3KD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录