Is there a way for you to spawn an NPC based on a player?

Hi.

I’m adding a sort of “Developers” area in my game, in which NPCs of said developers would spawn.

I’ve tried adding in the NPCs manually, but then if they change their avatar- it looks off.

I tried using some LoaderModel, but it doesn’t render packages or in R15.

Is there a way to…

  • Generate a HumanoidDescription or NPC based off a Username/UserID;
  • That has the user’s R15 animations loaded (and playing);
  • That can be run every minute or so to ensure it stays up to date

Could someone point me in the right direction?

2 Likes

you might want to use game.Players:GetHumanoidDescriptionFromUserId() and apply it to a npc. there isnt really a easier way in my eyes

3 Likes

The HumanoidDescription returned by GetHumanoidDescriptionFromUserId also has properties for the equipped animations FallAnimation, IdleAnimation, etc. You can load them to the NPC and play them yourself.

1 Like

You can just get the player model by using this function

2 Likes

That didn’t work well when I tested it. My character was mangled:

image

And the hierarchy of the model is weird:

2 Likes

Hmm, I totally forgot about the function’s behaviour. I’d go for Humanoid Descriptions then.

1 Like

exactly the same at me it messes up. the best guess is using humanoid descriptions since that one is most likely to succeed.

this is a really good explaination to go from

1 Like

When experimenting with this, I found that the NPC isn’t spawned with the animations the player already has. Is there a way to do this?

1 Like

it does spawn with the animations. create the humanoid description and parent it to the workspace. you’ll see the animation id’s in there. use those to play the npc’s animations

afbeelding

edit
the bound humanoid description is also located in the humanoid itself. you cna use it from there too so no need to parent the one you’ve gotten the description from

I’ve been debugging this and testing it for nearly half an hour now and it doesn’t seem to work.

local char = script.Parent
local desc = game.Players:GetHumanoidDescriptionFromUserId(47890485)
local animId = desc.IdleAnimation

char.Humanoid:ApplyDescription(desc)

local animation = Instance.new('Animation')
animation.AnimationId = "http://www.roblox.com/asset/?id="..animId
animation.Parent = char

print("http://www.roblox.com/asset/?id="..animId)

local track = char.Humanoid:LoadAnimation(animation)
track:Play()

After looking at things like API References and so on, I can’t find anything.

2 Likes

If your character, by any chance, Anchored? Make sure that all the parts are unanchored.

EDIT: Tested, and not the issue.

i’ve tried this methode of his. it idd doesnt work even if its unanchored. the chance is big he needs to get the full animate script and adjust it to the npc since, for some reason, a free modeled npc (just to test) does work fine with animations.

  • Not anchored

I tested it with a free model NPC and the character just fell apart.

Update
I put the default animation script into the NPC and it appears to be working. However, despite adding this to the script:

local description = script.Parent.Humanoid:GetAppliedDescription()
animNames.climb = "http://www.roblox.com/asset/?id=".. description.ClimbAnimation
animNames.fall.id = "http://www.roblox.com/asset/?id=".. description.FallAnimation
animNames.idle.id = "http://www.roblox.com/asset/?id=".. description.IdleAnimation
animNames.jump.id = "http://www.roblox.com/asset/?id=" .. description.JumpAnimation
animNames.run.id = "http://www.roblox.com/asset/?id=" .. description.RunAnimation
animNames.swim.id = "http://www.roblox.com/asset/?id=" .. description.SwimAnimation
animNames.walk.id = "http://www.roblox.com/asset/?id=" .. description.WalkAnimation

script.idle.Animation2.AnimationId = "http://www.roblox.com/asset/?id=".. description.IdleAnimation

It is not loading the individual users’ animations.

that’s because the animations are retrieved from the values In the script’s explorer as children. try to adjust those too and put a wait before you let the animations be played since it might error

In the script I updated the table for each animation and the physical value for idle. I added a wait(). This time the idle anim just doesn’t play, the other animations (triggered by pushing the NPC) appear as default RThro.

I took the animate script from my own character and put it in the NPC and it did my own animations.

Obviously this wouldn’t work if I wanted the NPC to suddenly be another user or if I changed my animations.

It turns out you’ll need to use InsertService:LoadAsset() to get the animation you want. This returns a rather deeply nested Model, though, with the animation you want at the end…

image

The following code runs… But please rewrite it to load Animation1 specifically. I just did game:GetService("InsertService"):LoadAsset(animId):GetChildren()[1]:GetChildren()[1]:GetChildren()[1] out of laziness.

local char = script.Parent
local desc = game.Players:GetHumanoidDescriptionFromUserId(47890485)
local animId = desc.IdleAnimation

char.Humanoid:ApplyDescription(desc)

local animation = game:GetService("InsertService"):LoadAsset(animId):GetChildren()[1]:GetChildren()[1]:GetChildren()[1]

game:GetService("InsertService"):LoadAsset(animId).Parent = workspace

local track = char.Humanoid:LoadAnimation(animation)
track:Play()

This also doesn’t handle characters that don’t have a custom animation loaded (since desc.IdleAnimation will be zero. You’ll need to handle that yourself. The default animation script has a handy table, for reference:

local animNames = { 
	idle = 	{	
				{ id = "http://www.roblox.com/asset/?id=507766666", weight = 1 },
				{ id = "http://www.roblox.com/asset/?id=507766951", weight = 1 },
				{ id = "http://www.roblox.com/asset/?id=507766388", weight = 9 }
			},
	walk = 	{ 	
				{ id = "http://www.roblox.com/asset/?id=507777826", weight = 10 } 
			}, 
	run = 	{
				{ id = "http://www.roblox.com/asset/?id=507767714", weight = 10 } 
			}, 
	swim = 	{
				{ id = "http://www.roblox.com/asset/?id=507784897", weight = 10 } 
			}, 
	swimidle = 	{
				{ id = "http://www.roblox.com/asset/?id=507785072", weight = 10 } 
			}, 
	jump = 	{
				{ id = "http://www.roblox.com/asset/?id=507765000", weight = 10 } 
			}, 
	fall = 	{
				{ id = "http://www.roblox.com/asset/?id=507767968", weight = 10 } 
			}, 
	climb = {
				{ id = "http://www.roblox.com/asset/?id=507765644", weight = 10 } 
			}, 
	sit = 	{
				{ id = "http://www.roblox.com/asset/?id=2506281703", weight = 10 } 
			},	
	toolnone = {
				{ id = "http://www.roblox.com/asset/?id=507768375", weight = 10 } 
			},
	toolslash = {
				{ id = "http://www.roblox.com/asset/?id=522635514", weight = 10 } 
			},
	toollunge = {
				{ id = "http://www.roblox.com/asset/?id=522638767", weight = 10 } 
			},
	wave = {
				{ id = "http://www.roblox.com/asset/?id=507770239", weight = 10 } 
			},
	point = {
				{ id = "http://www.roblox.com/asset/?id=507770453", weight = 10 } 
			},
	dance = {
				{ id = "http://www.roblox.com/asset/?id=507771019", weight = 10 }, 
				{ id = "http://www.roblox.com/asset/?id=507771955", weight = 10 }, 
				{ id = "http://www.roblox.com/asset/?id=507772104", weight = 10 } 
			},
	dance2 = {
				{ id = "http://www.roblox.com/asset/?id=507776043", weight = 10 }, 
				{ id = "http://www.roblox.com/asset/?id=507776720", weight = 10 }, 
				{ id = "http://www.roblox.com/asset/?id=507776879", weight = 10 } 
			},
	dance3 = {
				{ id = "http://www.roblox.com/asset/?id=507777268", weight = 10 }, 
				{ id = "http://www.roblox.com/asset/?id=507777451", weight = 10 }, 
				{ id = "http://www.roblox.com/asset/?id=507777623", weight = 10 } 
			},
	laugh = {
				{ id = "http://www.roblox.com/asset/?id=507770818", weight = 10 } 
			},
	cheer = {
				{ id = "http://www.roblox.com/asset/?id=507770677", weight = 10 } 
			},
}

I also don’t know how this would handle non-R15 characters.

4 Likes

This worked. Thank you. :slight_smile:

I was playing about with this and discovered that this happens. Do you know why, or how to fix it?