Character in a ViewPort Frame

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)

This might help: set Archiviable to true? (Archivable set to false prevents cloning/ destroying)

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

Why dont you use a normal rig, and apply its humanoid discription? This should set it up correctly:

1: GetHumanoidDescriptionFromUserId
2: humanoid:ApplyDiscription()

and for tools you can use humanoid:EquipTool()

1 Like

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

maybe try to add a worldmodel to the viewportframe

so make the dummy a worldmodel? or smth else

edit: wait that made it move and idle lol thanks ig

put the world model as a child of the viewportframe not like the dummy

it doesnt work ):

i just need a way to use ApplyDescription() on the client or another way to use on the server and still have the player see their character

try this maybe:

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)

no, it made 2 characters and its still normal dummy ):

Thats odd it seems to work fine for me…
Viewmodel.rbxl (60.4 KB)

bruh. it works in ur game but not in mine, i copy and pasted it

try to slowly add any code from your game to my file and see what could be breaking it

idk, i tried, maybe its game setting idk

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! :sweat_smile:

You could try using this module, I personally used it when I was making a Jumbotron.

i just changed some stuff and it worked, thanks everybody! i gotta give it to abcreator, but thats everybody!

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