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

"CharacterAdded is not a valid member of Players?"

How do i make a NPC look like a player ingame. I've done a ton of searching and seem to not get the answer. I'm trying to make it animated too at the same time.

Example: https://prnt.sc/kld0zl (a photo shows that a player is next to a model that looks just like them but without a hat.)

script:

	local cchar = plr.Character:Clone()
cchar:MoveTo(game.Workspace.charspawn.Position)
cchar.HumanoidRootPart.Anchored = true
end)```

Error: CharacterAdded is not a valid member of Players

1 answer

✓ Accepted answer

You can check out the PlayerAdded event here. You must set the Archivable property to true before you can edit a players character.

local players = game:GetService("Players")

local function clone(character)
	character.Archivable = true
	local cloned = character:Clone()
	character.Archivable = false
	return cloned
end

local function move(clone, newpos)
	local torso = clone:FindFirstChild("HumanoidRootPart")
	-- make sure torso is there
	if torso then 
		torso.Anchored = true
		clone:MoveTo(newpos)
		-- move clone
	end
end

players.PlayerAdded:Connect(function(player)
	-- When a player joins
	player.CharacterAdded:Connect(function(character)
		-- When a players character loads 
		delay(player.DataReady, function() 
		-- seems to help wait for everything to load
		local clonedCharacter = clone(character)
		-- clone it
		clonedCharacter.Parent = workspace
		-- parent it
		move(clonedCharacter,  Vector3.new(0,5,30) ) end)
		-- move it
	end)
end)

2 comments

0

there's a way to animate it right?

0

Yes, look up how to load NPC animations. There are relevant tutorials on SH, the dev forum, and on YouTube. 

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