I wrote this script which makes players fall down if they get to close to a part, it works fine, but whenever a player dies it glitches and doesn’t work. Can someone please help?
Hi Yellow, when your character dies, the HumanoidRootPart becomes nil as it has been removed from the game, therefore the part doesn’t exist and your code will trying to be index a Position from a nil part.
To fix this, you’d most likely want to check if humanoidrootpart exists and most likely run the while loop in a CharacterAdded event, thank you.
Thank you so much for your help, I’ll try to get it to work based off of the knowledge you have provided me.
@EdibleGames has identified the problem however a solution is still unclear.
Use the CharacterAdded
event of the player, and put the loop inside of it.
This isn’t working at all now.
This problem has still not been fixed.
Let’s use the edit feature instead of creating multiple posts. Anyway, move the HumanoidRootPart variable inside the function and use the character
parameter of the CharacterAdded event.
Yes, does it work? If not, are there any errors?
The problem is the script is still using the old humanoid root part’s position instead of the new one, we need to somehow like reset the position or something on death.
Instead of doing while wait() do
, use the conditional and do while HumanoidRootPart do
and put the wait()
statement inside of the loop. By the way, I would recommend using RunService.Stepped instead of wait()
.
Thank you so much for your help, but I figured it out, instead of using a variable which stored the humanoid root part I directly referenced it which worked!
if (Character.HumanoidRootPart.Position - TrollPart.Position).Magnitude < AgroDistance then
TrollPart.Transparency = 1
TrollPart.CanCollide = false
wait(1)
TrollPart.Transparency = 0
TrollPart.CanCollide = true
Again, thank you so much! I wouldn’t have been able to do it without all of your help!