Help with preview system using CFrame, WorldModel, and R15 rig

  1. What do you want to achieve? I’m trying to build a preview system for equipping items to an R15 rig. Note that these items aren’t going to a clone of a player, but a clone of an in-game R15. Think of it as a preview for an in-game mannequin on display

  2. What is the issue? When I add an item to the R15 via the AddAccessory option it puts it in the middle of the CFrame instead of on the models head. How can I properly add items to the existing model already in the CFrame?

  3. The Code
    Here is the script I’ve written so far. It clones a dummy rig, “Dummy1”, that is in a folder named “Player1Assets” within workspace. The adding of the hat happens at the very end of the script. I’m assuming there is some way to set the position of items added but I’m at the end of my LUA/Studio knowledge which is why I’m reaching out for help.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local hat = ReplicatedStorage:WaitForChild("RomanHelmet")
local player = game.Players.LocalPlayer
local character = workspace.Player1Assets.Dummy1

local VPFcam  = Instance.new("Camera")
VPFcam.Parent = script.Parent.ViewportFrame
VPFcam.CFrame  = CFrame.new(0,0,0)
script.Parent.ViewportFrame.CurrentCamera = VPFcam

repeat wait(.1) until game:IsLoaded()

character.Archivable = true

local ClonedChar = character:Clone()
ClonedChar.Name = "StatueDummy"


ClonedChar.Parent = script.Parent.ViewportFrame.WorldModel
ClonedChar:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0,0,-9.5), Vector3.new(0,0,0)))
wait(2)
--Add Hat
ClonedChar.Humanoid:AddAccessory(hat)
1 Like

try this it inserts from roblox with asset id instead of getting it from replicated storage. i remember awhile ago i ran into this exact problem. it doesnt make sense why your way doesnt work but idk. let me know if this works

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local character = workspace.Player1Assets.Dummy1

local VPFcam  = Instance.new("Camera")
VPFcam.Parent = script.Parent.ViewportFrame
VPFcam.CFrame  = CFrame.new(0,0,0)
script.Parent.ViewportFrame.CurrentCamera = VPFcam

repeat wait(.1) until game:IsLoaded()

character.Archivable = true

local ClonedChar = character:Clone()
ClonedChar.Name = "StatueDummy"


ClonedChar.Parent = script.Parent.ViewportFrame.WorldModel
ClonedChar:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0,0,-9.5), Vector3.new(0,0,0)))

wait(2)
--Add Hat
local model = game:GetService("InsertService"):LoadAsset(177433156) -- inserts from roblox with asset id instead of getting it from replicated storage
model.Parent = workspace
local Children = model:GetChildren()
for i,v in ipairs(Children) do
	v.Parent = ClonedChar
	wait()
	model:Destroy()
end
1 Like

Thank you so much! I honestly can’t believe someone was able to provide a solution this quickly, I figured I was out of luck.

Like you mentioned, it is weird I’d have to use InsertService instead of pulling from ReplicatedStorage so I’m going to spend some time playing with the code. I’m also not familiar with InsertService and any performance issues with that. As I mentioned this is a preview system so someone, or multiple people at once, could be clicking through inventory items to see how they look on the dummy and I have concerns about that. I’m not sure if you can shed any light on InsertService and if it should be fine for my use case or not. I’ll reference the API’s later tonight or tomorrow when I have more time.

Thanks again for the help!

1 Like

well i’ve never tried it with a public game, but i used it with an avatar editor once and rapidly clicked through the hats and it seemed pretty smooth and i didnt have any lag or anything so it might be fast enough even with many players clicking through items but im not sure

1 Like