How do i paste the LocalPlayers Appearance to a rig in the workspace?

Hey, it’s my first post on the forum.

  1. What do you want to achieve? Keep it simple and clear!
    Paste the LocalPlayer’s appearance to a “Rig” in the workspace, where each player can see their own avatar. The following “Rig” should look like my character.
    image

  2. What is the issue? Include screenshots / videos if possible!
    image
    Rig just stays the same.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I was wondering if i have to have both a local script and a server script to handle the LocalPlayer “Appearance” and “Description”.

This is my current script: (Currently in StarterPlayerScripts, in a Local Script)

local Oldhumanoid = game.Workspace:FindFirstChild("Rig").Humanoid
local localPlayer = game.Players.LocalPlayer
local function applyAppearance()
	local humanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(localPlayer.UserId)
	task.wait(0.5)

	local Newhumanoid = Oldhumanoid:Clone()
	Newhumanoid.Parent = game.Workspace:FindFirstChild("Rig")
	Oldhumanoid:Destroy()
	Newhumanoid:ApplyDescription(humanoidDescription)
end

applyAppearance()

Thanks for reading and thanks for any help!

1 Like

You’re gonna have to split this into a localscript and a server script because I’m pretty sure Players:GetHumanoidDescription or Humanoid:ApplyDescription are server only.
Also, make a RemoteEvent anywhere except ReplicatedFirst, StarterGui, and friends.

LocalScript:

local RemoteEvent: RemoteEvent -- location of the RemoteEvent you made
local Oldhumanoid = game.Workspace:FindFirstChild("Rig").Humanoid

local function applyAppearance()
      RemoteEvent:FireServer(Oldhumanoid)
end

Server Script:

local RemoteEvent: RemoteEvent --Same thing
RemoteEvent.OnServerEvent:Connect(function(Player, Oldhumanoid)
        local humanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(Player.UserId)
        task.wait(0.5)
        
        Oldhumanoid:ApplyDescription(humanoidDescription)
end)

EDIT: Yes you have to do a ServerScript because the changes you make on a LocalScript don’t save for anybody else, and as I said above some of the methods you use just don’t work on client-sided scripts.

1 Like

Thanks for the reply.

Ive added these two scripts, but i still get this error:

Players.GOPPRO99.PlayerScripts.CustomRig:2: attempt to index nil with ‘Humanoid’ - Client - CustomRig:2

Linked to this script: (This is the local script in starterplayerscripts)

Im not sure why it cant find the “Humanoid”

try waiting for child “Humanoid”. Localscripts don’t have immediate access to the character’s humanoid at least in studio

1 Like

Now i get no errors from the output, yet the rig remains intact

1 Like

Welcome to the DevForum! Let me help you with your problem.

An “attempt to index nil with '...'” error stems from you trying to index nil.

This is easily demonstratable with this piece of code:

print( (nil).Name ) -- attempt to index nil

Since nil represents, well, nothingness, this produces an error.

In your code, this means that whatever you’re trying to index with Humanoid, is nil. This means that:

game.Workspace:FindFirstChild("Rig")

is nil. Try to verify that the Rig named “Rig” is parented directly to the Workspace. If it is, and FindFirstChild is returning nil, that probably means it hasn’t loaded yet, and so you can use WaitForChild.

@RDJpower is correct in that Humanoid:ApplyDescription can only be called from the server. You should try their solution and see if it works.

1 Like

Did you make/clone the Humanoid on a LocalScript? If so, try moving that script to the server.

I’m curious about what you are using this for. What’s your use case? There are definitely cases where a RemoteEvent can be avoided, depending on what you actually need.

The “Rig” Is is parented to the workspace:
image

I get no errors when playing.

Now, for some reason, the “Rig” ApplyDescription is not working and the rig stays default.
Im using @RDJpower 's scripts. One in starter player scripts and the other in serverScriptService

Possibly the “Rig”'s descendants might be causing the problem?

BTW thanks for the help, i rlly appreciate it

I want to copy the humanoids apprearence, ie, make the rig look like the players avatar

My goal is to make an NPC which looks like the player playing the game. The rig would be in the workspace and every user would see their own avatar

Scripts (with RunContext property set to Legacy) don’t run in ServerStorage. Parent them to ServerScriptService to make them run.

My bad, typo, i meant serverscriptservice

1 Like

Did you remember to call the applyAppearance function on the client?

Does the remote event fire? I see immediate access before you fire to the server

Now this completely changes things.

With the current setup, if another player joins the game, then the appearance of the npc for everyone will change to the newest player. This is definitely not what you want.

I looked around Players’ service methods, and there’s Players:CreateHumanoidModelFromUserId, which, by the way, does work on the client!

Remove the current RemoteEvent setup and go back to your one LocalScript. Change the applyAppearance function to this:

local function applyAppearance()
	-- This creates a new Model that resembles the player
	local playerModel = game.Players:CreateHumanoidModelFromUserId(localPlayer.UserId)

	playerModel.Name = "Rig" -- Give it the same name as Rig

	-- Sets the pivot (location) to where the Rig was
	playerModel:PivotTo(game.Workspace.Rig:GetPivot())
	-- Destroys the Rig since it is now not needed
	game.Workspace.Rig:Destroy()

	-- Parent rig to workspace
	playerModel.Parent = workspace
end

EDIT: Added some missing things to the code snippet.

EDIT 2:

The documentation for Players:CreateHumanoidModelFromUserId states:

Returns a character Model set-up with everything equipped to match the avatar of the user specified by the passed in userId. This includes whether that character is currently R6 or R15.

The fact that it will vary from R6 to R15 depending on the player model could be an issue. Good thing that there’s also Players:CreateHumanoidModelFromDescription, which you can use in conjunction with Players:GetHumanoidDescriptionFromUserId (it works on the client!). Using these methods, you can force the player model to be R6:

local function applyAppearance()
	-- Get player's HumanoidDescription
	local playerHumanoidDescription = game.Players:GetHumanoidDescriptionFromUserId(localPlayer.UserId)

	-- Create a Model that resembles the player, and also force them to be R6
	local playerModel = game.Players:CreateHumanoidModelFromDescription(
		playerHumanoidDescription,
		Enum.HumanoidRigType.R6
	)

	playerModel.Name = "Rig" -- Give it the same name as Rig

	-- Sets the pivot (location) to where the Rig was
	playerModel:PivotTo(game.Workspace.Rig:GetPivot())
	-- Destroys the Rig since it is now not needed
	game.Workspace.Rig:Destroy()

	-- Parent rig to workspace
	playerModel.Parent = workspace
end

Take care!

2 Likes

Oh wow I didn’t even know that existed! Good to know.

1 Like

That works perfectly. Thank you so much for your help. I really appreciate it. Thank you also to @RDJpower and @Placewith5s. Im going to give Emmie the solution as it finally worked for me.

Appreciate your help guys!
Have a good day!

1 Like

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