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

HumanoidRootPart is not a valid member of Model?

Asked by
TechModel 118
3 years ago
Edited 3 years ago

Hello! I wanted to know how to fix this. Looks normal if you say so. However, what I've encountered was when I fall into the void, it sends that error, breaking the script and no longer able to run. How do I fix this? Thanks. Also, it is run on a loop so don't know how to reset it and make it work again then to leave and rejoin.

local distance = (player.Character.HumanoidRootPart.Position - Floaty.PrimaryPart.Position).Magnitude

1 answer

Log in to vote
1
Answered by 3 years ago

When a character dies this error will appear if you try to access any part of the character model. To get around this you just have to get used to doing checks. For instance, before you do what you are currently doing, add this:

local hrp = player.Character:FindFirstChild("HumanoidRootPart")
if hrp and player.Character.Humanoid.Health > 0 then
    local distance = (hrp.Position - Floaty.PrimaryPart.Position).Magnitude
end

Simple enough, just make sure the script is only running if you can find everything you need to run it. Let me know if this still doesn't work.

0
Thank you TechModel 118 — 3y
Ad

Answer this question