Attempt to index nil with 'Parent'

Yo, I’m currently working on a ragdoll system that will clone the player when they die/respawn.

I know that there’s a simple answer to this, and that’s to have a check to make sure that the character isn’t nil. That still leaves me with the issue of cloning the player as they die/respawn.

The error is line 3. char:Clone().Parent = game.Workspace, this is happening due to the character instantly respawning… as you can see in the photo provided. I’m unsure of a good way to counter this, that’s also efficient to use.

image

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterRemoving:Connect(function(char)
		char.Archivable = true;char:Clone().Parent = game.Workspace
	end)
end)
2 Likes

This error is happening because you are trying to clone the character when it doesn’t exist. Instead try player.CharacterAdded()

3 Likes

yup 100% agreed w choco.

not sure how to do it for each time the character resets but this works for everytime a player joins the game:

game.Players.PlayerAdded:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	wait() -- u gotta put a wait here otherwise ur character will be grey. this brings all the accessories.
	char.Archivable = true
	local copy = char:Clone()
	copy.Parent = workspace
end)

credits:

1 Like

@Chocolatemilk221 @targetframed

Thank you for the information! I shall update my code accordingly…

Sorry, I worded this post poorly. I need to clone the character when the player dies/respawns. The error is line 3. char:Clone().Parent = game.Workspace, this is happening due to the character instantly respawning… as you can see in the photo provided above. Which is why I was using Character Removing.

Any ideas?

2 Likes

np! :slight_smile:

i found this post which im reading thru it rn. it may help u

2 Likes

This is my own post, I’ve already attempted this; and it doesn’t work sadly.

1 Like

You could try to do the Humanoid.Died and then try to clone it. This will make the character be cloned the second the player dies.

3 Likes

oh damn i didnt read the username :man_facepalming:

1 Like

i actually figured out what was going wrong. im pretty sure this is what ur looking for? when the character resets and on respawn their character will clone.

here’s the script:



game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
	
	wait(.5)
	char.Archivable = true
	local copy = char:Clone()
	copy.Parent = workspace
	
end)
end)
1 Like

@targetframed @Chocolatemilk221
If you’re willing to help, I’ve created a mega thread regarding the issues. The Humanoid.Dieddoes work, but now the players character doesn’t respawn after dying.

Here’s the post where I’ll be continuing this.

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