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.
What is the issue? Include screenshots / videos if possible! Rig just stays the same.
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()
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.
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.
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.
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?
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.
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.
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
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.