After a character dies the script is not able to find the hrp. Even if I put a :WaitForChild on it it yields infinitely. I’ve searched for the topic before posting and I couldn’t find any case where the solution isnt somthing I haven’t tried or unrelated to my problem, here’s my code:
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local hrp = Character:WaitForChild("HumanoidRootPart") -- I used to have Character.HumanoidRootPart but neither work
These are the first Lines of a script and I have a Humanoid.Died:Connect() function later but it does unrelated stuff and the error Studio sends traces back to Line 4. For some reason it reruns the entire script after a player dies and cant find the hrp. Thanks in advance
local hrp = (function()
repeat task.wait() until char:FindFirstChild("HumanoidRootPart")
return char.HumanoidRootPart
end)()
Basically its a lambda function that waits for the humanoidrootpart to exist and then gives it to you, and u can use it the same way u would use it normally, like
yes I am sure that has nothing to do with the hrp of the character (and also both r6/r15 have hrps)
You sure? Did you even check?
and yeah basically, the rootpart in Humanoid (which is just an attribute/property) which is basically the PrimaryPart of the character, which in most cases is humanoidrootpart (I think all cases even) , unless it’s a custom character
You are only getting the character on the start of the script. When the character dies it gets removed and when it loads back your script still has your old character.
To fix this you have to update the character using the player.CharacterAdded event or something else you might think of.