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

Why is my player's HumanoidRootPart.Position becoming stuck on death/reset?

I have a script that is dependent on the player's position. it works fine, but when I die and respawn the player's position freezes and pretty much stays on the position they either died or went to reset from.

Is there a way to reset this? I am using Roblox's built in Reset so I honestly don't know what to do.

this is in StarterGUi

print("CHARACTER POSITION: ", character.HumanoidRootPart.Position)

This was simply for debugging. When I first start, it constantly changes when I move around. But when I respawn/reset, I notice that it never changes, and the script is running over and over. The position is stuck.

Is there a way to fix this? Like say that when the player resets or dies I fix the HumanoidRootPart position?

7 comments

0

this happens because after death the character becomes "null", try to update the variable after death, maybe it works

0

Is it the same for reset?

0

Wait, this doesn't make any sense. How does my character become "null"? After reseting or dying and respawning I'm still able to be attacked and wear armor, and those are dependent on the character. I'm going to try using the player's head instead or something, I hope that one ain't bugged too. This is honestly frustrating and I don't why this bug still exists.

0

Alright I solved it using some remote events/functions. The server appears to know they've reset and can still follow the position, so I just sent that back to this script.

0

I think what HasteeD was saying is that when the player dies they become Nil, nothing, and theres no longer a humanoid to get the position of. When they reset the script continues to track the "nil" characters location.

1

What happens when you reset is that your character gets destroyed and is cloned in as a new character when you respawn. So the original hrp you are referencing doesn't exist anymore, it's a whole new hrp

0

I tweaked my answer slightly, has this worked?

1 answer

✓ Accepted answer

You can use the :CharacterAdded() listener to renew the Current Character. It's important to know that after a Character resets, a completely new one is passed. Setting the original reference to the diseased Character to NULL, as it's no longer existent. The Listener would look like so

local Player = game:GetService("Players").LocalPlayer
Player.CharacterAdded:Connect(function(Character)
	repeat wait() until workspace[Character.Name]
	local CharacterPos = Character.Position
end)

Hope this helps! don't forget to press accept! Something wrong or don't understand? please comment!

5 comments

0

CharacterAdded is an event not a function (facepalm)

0

?

0

Line 3 will error. Besides, the event passes the character as an argument, so no need to do that.

0

I'll try to see if this works. I have it working now using remote events and functions but this looks simpler and if I can get it work this way, all the better.

0

This works too. Sorry for taking a while to accept the answer. If I use this, all I need to do is send the CharacterPos to the pickupScript and it works. Thank you.

This discussion is preserved as it was. New answers, comments, and votes are closed.