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.
✓ ANSWER ACCEPTED
Clear Starterpack on death?
2 answers
✓ Accepted answer
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
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)
2 comments
0
This script will only work for the first death.
0
Thanks! In the future I may use this on another game.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thank you it works perfectly :)