Hello there! I am working on a game and as how many simulators / tycoons use NPC’s looking like their friends, I decided to try doing it. However when Applying the description to the rig, it errors that ‘it cannot be ran in the backend’.
I would like to note the fact that this code is written inside a ModuleScript and called on a LocalScript:
RigFriend - Main:
function RigFriend.LoadRigWithCharacterAppearance(UserId: number)
local rig = replicatedStorage:WaitForChild("Assets").Rig_R6
rig:Clone()
rig.Parent = workspace.Rigs
rig.Humanoid:ApplyDescription(players:GetHumanoidDescriptionFromUserId(UserId))
end
The issue is that :ApplyDescription() and :GetHumanoidDescriptionFromUserId() are server-only, so when you try to use them from a LocalScript (or anything the client touches), it throws that “can’t be run in the backend” error.
What you’ll wanna do is move that part of the code — the bit where you get the HumanoidDescription and apply it — to a server-side script. You can still have your LocalScript request it, but the actual applying has to be done on the server.
One way to fix it:
Keep your ModuleScript on the server (like under ServerScriptService)
Create a RemoteEvent in ReplicatedStorage called like RequestFriendRig
From the LocalScript, fire that RemoteEvent and pass in the UserId
Then on the server, when it receives that event, it runs the code to clone the rig, get the description, apply it, and parent it to workspace
Super simple version of the server-side bit:
remote.OnServerEvent:Connect(function(player, userId)
local rig = replicatedStorage.Assets.Rig_R6:Clone()
local description = players:GetHumanoidDescriptionFromUserId(userId)
rig.Parent = workspace.Rigs
rig.Humanoid:ApplyDescription(description)
end)