Parent of model locked to NULL immediately upon creation

I have a module script required by a server script that generates an R6 character model from scratch when a new round begins; however, when I create the model, the game will not allow me to parent it to the workspace.

function SpawnPlayer(player, pos)
   local NewChar ="Model", workspace.Participants)
   --creates all the limbs and joints and humanoid, etc. etc.
   player.Character = NewChar

When I tested this, I noticed that the Character property of my player wasn’t nil, but the actual character model was not in the workspace like it was supposed to be. So I added a redundant line at the end of the function:

   NewChar.Parent = workspace.Participants

And then it gives me the error that the model’s parent property is locked to NULL.
I quadruple-checked every script involved in the process to make sure it wasn’t being destroyed and reparented, but it wasn’t.
Further, I’ve used this exact script for a while and it’s never thrown this error before.

Is there something I’ve missed, or is it a glitch with Studio? I can’t see another reason why I wouldn’t be allowed to set the parent of a model I just created.

You can’t set the parent twice without waiting. Take out the redundant line.

1 Like

That stopped the error from showing, but the model still isn’t being parented to the workspace.

Even when I add a wait() line before setting the parent, or set the parent immediately after creating the model, the error is still thrown and the model is never put in the workspace

Don’t assign the parent with an Instance new. That has been deprecated.
do this…
local NewChar =“Model”)

then after you create the parts and assign them into the model, then do
local NewChar.Parent = workspace.Participants

1 Like

It is incorrect that,parent) has been deprecated.

As to why the model is not showing, are you sure it’s not showing? Currently it is just named “Model” so that’s what it will show up as in workspace.

After doing further testing, I’ve deduced the issue occurs when setting player.Character to the new model.

When I completely remove the line player.Character = Char, the model does appear in the workspace; however, the instant I set player.Character to Char, it disappears from the workspace.

Even stranger, when player.Character changes, the old character model also disappears from the workspace even though there’s not a single script that removes it. And in the end player.Character is still set to the old model instead of the new one.

I have no idea what to think of this, and have looked all over the forum for issues like this but haven’t found any solutions that work

It was at one time.
It used to give a warning in studio, when you would put a second parameter.
Maybe they removed it, but a one time it definitely used to come up as that.

Thanks for the correction.

Its probably related to the HumanoidRootPart
Does the new Character have a HumanoidRootPart (and a Humanoid for that matter)?

This is backend Roblox code that runs when setting Player.Character. Roblox tends to run code when setting Player.Character, so it’s best to use Player:LoadCharacter(). However I found that setting Player.Character = to a character with a Humanoid automatically adds player controls to that character.

Of course!

1 Like
function SpawnPlayer(player, pos)
	local NewChar ="Model")
	--creates all the limbs and joints and humanoid, etc. etc.

	player.Character = NewChar
	NewChar.Parent = workspace.Participants

This should fix it.

That makes so much sense now! I have this other server script that removes a player’s character and sets it to a blank model when they join, but forgot that I have Players.CharacterAutoLoads set to false, so I don’t need to that.

I guess me deleting a character that never actually existed and then replacing it with a blank model and then replacing it with an actual humanoid character somehow confused Roblox’s backend code?

Either way, removing the part that set the character to a blank model seemed to fix the issue entirely. Sorry for leaving that out :persevere:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.