so, im trying to make a viewport frame with the character (by cloning it) and make it spin (or the camera), but its not working, idk why, i’ve tried looking on devfourm posts and even chatgpt but i can’t find any that work. i’m trying to make a loadout system and i want it to show the character.
also, just wondering if you put a tool in the character will it show?
local viewportFrame = script.Parent
local Players = game.Players
function displayPlayerAvatar(player)
local avatarModel = Players:CreateHumanoidModelFromUserId(player.UserId)
local clonedAvatar = avatarModel:Clone()
clonedAvatar.Parent = viewportFrame
clonedAvatar.Position = Vector3.new(0,0,-5)
end
displayPlayerAvatar(Players.LocalPlayer)
please help if you can, thanks!
(i will mark correct if it works)
local viewportFrame = script.Parent
local Players = game.Players
function displayPlayerAvatar(player)
local avatarModel = Players:CreateHumanoidModelFromUserId(player.UserId)
avatarModel.Archivable = true
local clonedAvatar = avatarModel:Clone()
clonedAvatar.Parent = viewportFrame
clonedAvatar:WaitForChild("HumanoidRootPart")
clonedAvatar.PrimaryPart = clonedAvatar:FindFirstChild("HumanoidRootPart")
if clonedAvatar.PrimaryPart then
clonedAvatar:SetPrimaryPartCFrame(CFrame.new(0, 0, -5))
end
end
displayPlayerAvatar(Players.LocalPlayer)
``
just fixed some stuff, and it works fine, but my accesories are all over the place
From what I can tell; this is because accessory welds rely on physics simulation to work and the CreateHumanoidModelFromUserId function doesn’t set the accessory positions itself manually. You can solve this part of the issue by parenting the character to somewhere that runs physics simulation (ideally a WorldModel), for at least one physics heartbeat (RunService.Heartbeat) so the accessory positions are set correctly
Alternatively, you can use the ApplyDescription method, fetching first via GetHumanoidDescriptionFromUserId (as mentioned above). It seems that even while using the ApplyDescription method, you’ll unfortunately still need to first parent the model to a container which runs physics simulation before running the function since it doesn’t seem to work without it (again, a WorldModel would probably be most ideal here to run the physics simulation). By using this, it seems that you can eliminate the extra one-frame delay hack which is needed in the previous method. The big caveat here though is that iirc the player’s set HumanoidRigType wouldn’t be respected and you’ll need to manually handle loading R6/R15 rigs as needed, if that matters for your use-case. So in all-reality, this solution mightn’t be worth it depending on whether you want to support just one of the RigTypes, or both.
Theoretically, if none of these options work, you could probably manually calulcate the accessory positions yourself, but that’d almost certainly be over-kill.
im trying to use apply desc, but it can only run on server, and im trying to make like a loadout system and i want it to show the the players character ONLY, so i dont know. i need to somehow do it on the client, and i dont even know how to use heartbeat… im also a new dev, so just keep in mind lol
local viewportFrame = script.Parent
local Players = game.Players
function displayPlayerAvatar(player)
local char = player.Character or player.CharacterAppearanceLoaded:Wait()
char.Archivable = true
local avatarModel = char:Clone()
char.Archivable = false
avatarModel.Parent = viewportFrame
avatarModel:WaitForChild("HumanoidRootPart")
avatarModel.PrimaryPart = avatarModel:FindFirstChild("HumanoidRootPart")
if avatarModel.PrimaryPart then
avatarModel:SetPrimaryPartCFrame(CFrame.new(0, 0, -5))
end
end
displayPlayerAvatar(Players.LocalPlayer)
Despite the error not mentioning it (and it being a bit misleading because of that), the method is allowed to run on the client if the Humanoid was created on the client. Cloning a rig on the client still counts as the Humanoid (within the clone) being created on the client, allowing you use ApplyDescription on the client for it; you can use that trick as a workaround if you’d like.
Feel free to ask any further questions or clarifications you may have! By the way, apologies if the way which I’ve explained anything here is any bit confusing!