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

Clear Starterpack on death?

Asked by 3 years ago

Can anyone send me a code that clears your starterpack when you die? I'm making a game but it breaks whenever you hold out an item while you're dead.

2 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

Hope this works. Put this script in starterCharacter so it gets parented to the character even when you respawn

Put this in a script not a local script.

local Character = script.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
if Player then -- Make sure the script that is running is inside the Character
    local Humanoid = Character:WaitForChild("Humanoid")
    Humanoid.Died:Connect(function(Character) -- This runs as soon as someone dies
        -- Remove the tools that are unequipped
        for _, Tool in pairs(Player.Backpack:GetChildren()) do
            if Tool:IsA("Tool") then
                Tool:Destroy()
            end
        end
        -- Remove the tools that are equipped
        for _, Tool in pairs(Character:GetChildren()) do
            if Tool:IsA("Tool") then
                Tool:Destroy()
            end
        end
    end)
end
0
Thank you it works perfectly :) Cool29375 7 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Hope this works for you :)

local Player = game.Players.LocalPlayer
local Character = Player.CharacterAdded:Wait()

Character:WaitForChild("Humanoid").HealthChanged:Connect(function(health)
    if health <= 0 then
        for _,v in pairs(Player.StarterGear:GetChildren()) do
            v:Destroy()
        end
    end
end)
0
This script will only work for the first death. Kyokamii 133 — 3y
0
Thanks! In the future I may use this on another game. Cool29375 7 — 3y

Answer this question