Hi Developers,
I’m working on a character customization system that uses ViewportFrames to preview items before equipping. I’m encountering an issue specifically with the orientation of certain accessories (hats, in this case) within their preview viewports.
The Problem:
While most items display correctly in their ViewportFrame previews, some accessories (specifically those created using the Accessory Fitting Tool where the initial orientation might have been flipped) appear rotated incorrectly in the preview. However, when the player equips these same accessories, they attach to the character with the correct orientation. This discrepancy is only happening in the ViewportFrame preview for every frame.
Potential Cause & What I’ve Tried:
My suspicion is that the incorrect preview orientation matches the orientation shown by the Accessory Fitting Tool during the creation process if it was initially misaligned. I noticed that adjusting the rotation settings within the Accessory Fitting Tool only affects the final equipped orientation on the character, not the orientation within the ViewportFrame preview.
Relevant Setup:
I have a script (Viewport adder) that dynamically creates these preview frames. It clones the template frame(Frame under Viewport Adder) and the item itself (v) into the viewport structure:
Note: The same content for each section.
Viewport adder script(This adds each view port frame for each individual item, to under Head list. The viewport frames are clones of the Frame template under the viewportAdder script):
for _,v in pairs(game:GetService("ReplicatedStorage").Appearance.Head:GetChildren()) do
print(v)
local f = script.Frame:Clone()
local c = v:Clone()
print(v, f, c)
f.Parent = script.Parent
c.Parent = f.Background.Viewport
end
(IMPORTANT) Handler local script(camera rotation for the viewport):
repeat wait() until script.Parent:FindFirstChildWhichIsA("Accessory") or script.Parent:FindFirstChildWhichIsA("Hat") ~= nil
local model = script.Parent:FindFirstChildWhichIsA("Accessory") or script.Parent:FindFirstChildWhichIsA("Hat")
local cam = Instance.new("Camera")
model.Handle:Clone().Parent = script.Parent
model = script.Parent.Handle
model.Position = Vector3.new(0,0,0)
cam.Parent = model
cam.FieldOfView = 7
cam.CFrame = CFrame.new(Vector3.new(0,-1,20), model.Position)
script.Parent.CurrentCamera = cam
Model rotation(not important)
repeat wait() until script.Parent:FindFirstChild("Handle") ~= nil
local model = script.Parent:FindFirstChild("Handle")
game:GetService("RunService").RenderStepped:Connect(function()
model.Orientation = Vector3.new(0, model.Orientation.Y + 0.2, 0)
end)