HumanoidRootPart Is not a valid member after dying

So I made this script to launch the player back after activating the tool but If the player dies then tries to use the tool again it doesn’t work and I just get the error that HumanoidRootPart is not a valid member of my character. Here is the script:

local tool = script.Parent

local Player = game.Players.LocalPlayer

if not Player.Character then
	Player.CharacterAdded:Wait()
end

local character = Player.Character

local humanoid = character:WaitForChild("Humanoid")


local function getModelMass(model: Model): number
	local mass = 0

	for _, v in ipairs(model:GetDescendants()) do
		if v:IsA('BasePart') then
			mass += v:GetMass()
		end
	end

	return mass
end

local backwardsForce = getModelMass(character) * 85 

tool.Activated:Connect(function()
	humanoid.PlatformStand = true
	character:FindFirstChild("HumanoidRootPart"):ApplyImpulse(-character.HumanoidRootPart.CFrame.LookVector.Unit * backwardsForce)
	wait(.1)
	tool.Parent.Humanoid.Health = 0
end)
1 Like

A few ideas could be tested whether they were the issue or not:

  1. HumanoidRootPart doesn’t have collisions and fall right through the world.
  2. HumanoidRootPart is deleted after death, could it be an intended behavior(by engine?) or was it done by an external detail(not within the script)?

After dying I opened my player character and selected Humanoid root part and its at the right position and its still there

Where? Because At the top of the script I already do that.

Nevermind, figured out that the issue isn’t from the first :FindFirstChild(), it’s from the argument. I fixed it by rewriting into this:

tool.Activated:Connect(function()
	local HumanoidRootPart = character:FindFirstChild("HumanoidRootPart")
	
	if HumanoidRootPart then
		humanoid.PlatformStand = true
		HumanoidRootPart:ApplyImpulse(-HumanoidRootPart.CFrame.LookVector.Unit * backwardsForce)
		wait(.1)
		tool.Parent.Humanoid.Health = 0
	end
end)

I tried your code but now it doesnt error. But it still doesnt launch me back after the player dies.

Something must have stopped in its tracks in:
if HumanoidRootPart then

I am not able to tell what the issue is, try printing something after the if statement to assure that it is passing the if condition or not. If it does and the character doesn’t quite launch, try adding more power.

Ok I added a bunch of them and after the player dies they only go to (Passed Humanoid) then stop

local tool = script.Parent

local Player = game.Players.LocalPlayer

if not Player.Character then
	Player.CharacterAdded:Wait()
end

local character = Player.Character

local humanoid = character:WaitForChild("Humanoid")


local function getModelMass(model: Model): number
	local mass = 0

	for _, v in ipairs(model:GetDescendants()) do
		if v:IsA('BasePart') then
			mass += v:GetMass()
		end
	end

	return mass
end

local backwardsForce = getModelMass(character) * 85 

tool.Activated:Connect(function()
	print("Activated")
	local HumanoidRootPart = character:FindFirstChild("HumanoidRootPart")
	print("Passed Humanoid")

	if HumanoidRootPart then
		print("HumanoidFound")
		humanoid.PlatformStand = true
		HumanoidRootPart:ApplyImpulse(-HumanoidRootPart.CFrame.LookVector.Unit * backwardsForce)
		print("Applied Pulse")
		wait(.1)
		tool.Parent.Humanoid.Health = 0
		print("Player Died")
	end
end)