Character Scaling not working on NPC

What do you want to achieve?
I want to change the scale of an NPC that has a humanoid description of an avatar.

What is the issue? Include screenshots / videos if possible!
The issue is that the Values of the Humanoid Description aren’t loading fast enough for my code, and I’ve been trying things to wait for it to load. (The BodyheightScale is nil).

image

What solutions have you tried so far?
I’ve tried putting a RunService.Heartbeat:Wait(), I tried constantly using a while wait() do, and I tried to use repeat wait() until (obj) ~= nil.

Server Script
local userid = "2064158565"
local dummy = workspace:WaitForChild("Dummy")
local humanoid = dummy:WaitForChild("Humanoid")
local RunService = game:GetService("RunService")
local function CreateOfflineCharacter(UserID, Dummy)
	local Appearance = game.Players:GetHumanoidDescriptionFromUserId(UserID)
	Dummy.Humanoid:ApplyDescription(Appearance)
	local name = game.Players:GetNameFromUserIdAsync(userid)
	Dummy.NameDisplayDistance = 0
end

--The new animation
local ani = Instance.new("Animation", dummy)
ani.Name = "IdleAni"
ani.AnimationId = "http://www.roblox.com/asset/?id=507766388"
local animationtrack = humanoid:LoadAnimation(ani)

if humanoid then
	--Manipulate body size
	RunService.Heartbeat:Wait()
	local bodyheight = humanoid:FindFirstChild("BodyHeightScale")
	print(bodyheight)
	animationtrack:Play()
	animationtrack.Looped = true
end

--CreateOfflineCharacter function
local success, fail = pcall(function()
	CreateOfflineCharacter(userid, dummy)
end)

if success then
	print("Succeeded!")
end

if fail then
	warn("Failed!")
end

Thanks for your help!

I’m new to this whole scripting thing by the way.

2 Likes

NPCs normally don’t have those values, so you have to create them yourself.

Yes, but when I add the humanoid description they get added in anyways.

image

1 Like
Humanoid = 
if not Humanoid:FindFirstChild("BodyDepthScale") then
	local Value = Instance.new("NumberValue",Humanoid)
    Value.Name = "BodyDepthScale"
    Value.Value = 
else	Humanoid.BodyDepthScale.Value = 	end
if not Humanoid:FindFirstChild("BodyHeightScale") then
	local Value = Instance.new("NumberValue",Humanoid)
    Value.Name = "BodyHeightScale"
    Value.Value = 
else	Humanoid.BodyHeightScale.Value = 	end
if not Humanoid:FindFirstChild("BodyProportionScale") then
    local Value = Instance.new("NumberValue",Humanoid)
    Value.Name = "BodyProportionScale"
    Value.Value = 
else	Humanoid.BodyProportionScale.Value = 	end
if not Humanoid:FindFirstChild("BodyTypeScale") then
	local Value = Instance.new("NumberValue",Humanoid)
    Value.Name = "BodyTypeScale"
    Value.Value = 
else	Humanoid.BodyTypeScale.Value = 	end
if not Humanoid:FindFirstChild("BodyWidthScale") then
	local Value = Instance.new("NumberValue",Humanoid)
    Value.Name = "BodyWidthScale"
    Value.Value = 
else	Humanoid.BodyWidthScale.Value = 	end
if not Humanoid:FindFirstChild("HeadScale") then
    local Value = Instance.new("NumberValue",Humanoid)
    Value.Name = "HeadScale"
    Value.Value = 
else	Humanoid.HeadScale.Value = 	end

Eliminate what you don’t need.

3 Likes

image

The output goes to the else statement.

1 Like

Is this at the top of the script? Maybe try using WaitForChild.

2 Likes

image

Infinite yield :frowning:

Edit: I’m pretty sure this is because the body scalers aren’t automatically inside of the model. They’re added in when the humanoid appearance is set.

Oh I’m sorry!
A big mistake of mine xd
Put “not” before FindFirstChild.
PS: fix the script.

1 Like

There’s nothing in the output now, but nothing happens…

These kind of things are normally the simplest mistakes.

What if you just added a wait(2) at the top of the script to give it time to load in?

2 Likes

Nah nothing happens, just the same thing.

I also already have a RunService.Heartbeat:Wait() which should do the trick as I’ve used it on an unloaded character model before.

:confused:

Hmmm, and it is the only model named “Dummy” in the entire workspace?

1 Like

Yessir

Not enough characters

dhdashfahfadjfadfdasifhdasjfhdas

Could you add a print like this so that we can see what it thinks are the children.

print(humanoid:GetChildren())
2 Likes

It says… ... in the output.

:confused:

That is very weird. And have you tried just doing the simple thing of saying this:

humanoid.BodyDepthScale = 1 --or whatever you want

I’m confused. Am I supposed to set the value to …?

Modify the script a bit and add my own, animation doesn’t work, but scaling does.

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local userid = 2064158565
local dummy = workspace:WaitForChild("Dummy")
local humanoid = dummy:WaitForChild("Humanoid")

function CreateOfflineCharacter(UserID, Dummy)
    local Appearance = Players:GetHumanoidDescriptionFromUserId(UserID)
    humanoid:ApplyDescription(Appearance)
	--| Scale |--
    local Find = {
	    ["BodyDepthScale"] = 0.5,
    	["BodyHeightScale"] = 0.5,
	    ["BodyProportionScale"] = 0.5,
	    ["BodyWidthScale"] = 0.5,
	    ["HeadScale"] = 0.5
	}
    for Name,Val in pairs(Find) do
	    if not humanoid:FindFirstChild(Name) then
		    local Value = Instance.new("NumberValue",humanoid)
		    Value.Name = Name
		    Value.Value = Val
	    else humanoid[Name].Value = Val	end
	end
    -------------
--	local name = Players:GetNameFromUserIdAsync(userid)
    humanoid.NameDisplayDistance = 0
end

--The new animation
local ani = Instance.new("Animation", dummy)
ani.Name = "IdleAni"
ani.AnimationId = "http://www.roblox.com/asset/?id=507766388"
local animationtrack = humanoid:LoadAnimation(ani)

if humanoid then
    --Manipulate body size
    RunService.Heartbeat:Wait()
    animationtrack:Play()
    animationtrack.Looped = true
end

--CreateOfflineCharacter function
local success = pcall(function()
    CreateOfflineCharacter(userid, dummy)
end)
if success then		print("Succeeded!")
else				warn("Failed!")	end

Where are you putting it?
PS: how do you do this?
image

1 Like

No set it to a number value. Sorry I just put that there meaning you could put your number there. Basically, I was wondering if the BodyDepthScale wouldn’t come out as being a child, but maybe just saying Humanoid.BodyDepthScale could work.

2 Likes

Nah nothing happened there. (30)