Old character is destroyed when setting Player.Character to another value

When I set a Player.Character property to another character (or nil), their current character is automatically destroyed. I don’t know why this happens…

Expected behavior

I expect the old character to remain, so that I can use it as a ragdoll while a new character is assigned to them.

3 Likes

Parent the character to nil, set player.character to nil then represent the character to the original parent works as a workaround

2 Likes

What is the value of Workspace.PlayerCharacterDestroyBehavior?

1 Like

I think I’m experiencing this. Changing PlayerCharacterDestroyBehavior to either of it’s 3 values has no effect on my character disappearing, but disabling the line of code that sets Player.Character to nil upon death fixes it.

Not to mention that PlayerCharacterDestroyBehavior is a very ambiguous name when the only possible values are Default, Enabled and Disabled. What’s the behavior? I hope they change the name before starting the 3-phase rollout this seems to be (while accounting for code like ours).

1 Like

That is of the norm, I suggest you dupe the character beforehand and put it somewhere like server storage, and when you switch the character, teleport the duped one in storage to the old character and ragdoll it.

idk why you deleted that, but I’ve worked with changing Player.Character a lot, the old character will die when you set a new one, its like roblox reset. When you reset your character, it dies, and a new one spawns in.

Workspace.PlayerCharacterDestroyBehavior also has no effect for me, but I assume once it works it’ll be the fix I need. Parenting to nil and back seems to be the ideal workaround, as it doesn’t have to replicate a new character. It does trigger a parent change event from Workspace → Workspace → Workspace on the client though (sort of replication bug / weirdness).

Player.Character isn’t exactly fully predictable because the default PlayerScripts seem to expect a certain order of operations similar to the default character loading process. For example, parenting a new Character to Workspace before setting the property on the player, causes the character to not be initialised correctly. Is it possible this is also an undocumented order-of-operations issue?

To clarify, this property rather ensures Player characters are Destroyed rather than parented to nil and left there. This fixes possible memory-leaks depending on code setup. This property shouldn’t fix this issue as the property should already be functional and as you stated, this property does not currently fix this issue for you and is targeted at fixing a different issue.

4 Likes

Found someone to check this out! Thanks for the report. We’ll get back to you as soon as we have an update.

1 Like

That was what the property was originally intended to do, however, as of February 2024, they have been considering revising it to only apply to Player objects. I don’t think this change went through yet, but I wanted to mention it here as a PSA in case that does happen in the future:

There is little hope of changing this.

The engine removing the old character for you when setting Player.Character is the way things have worked since the beginning of Roblox and countless experiences likely depend on the behavior of the previous character being cleaned up automatically.

If you want some change here you will have to take the avenue of a feature request for more control over the behavior through additional settings.

4 Likes