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

Clear Starterpack on death?

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

✓ 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

1 comment

0

Thank you it works perfectly :)

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.