Viewport frame not working as intended

I have two NPCs currently in my game, and my chat GUI with them includes a viewport frame that renders their model as shown:


However, my second NPC, who has a different orientation when compared to the first, does not render correctly. The NPC is facing away from the camera in this case. I tried simply changing the orientation of the clone’s hrp but it didn’t work as intended. Any help would be appreciated, thanks!

Code that worked for the first NPC but not the second:

local clone = npc:Clone()
clone.Parent = player.PlayerGui.NPCConversation.TextButton.Frame.ViewportFrame.WorldModel
clone.PrimaryPart.Position = Vector3.new(0, 0, 0)
clone.PrimaryPart.Orientation = Vector3.new(0, 0, 0)

local viewportCamera = Instance.new("Camera")
viewportCamera.Parent = player.PlayerGui.NPCConversation
viewportCamera.CFrame = CFrame.lookAt(clone.Head.Position-Vector3.new(-0.5, 0.5, 3), clone.Head.Position-Vector3.new(0, 0.5, 0))
player.PlayerGui.NPCConversation.TextButton.Frame.ViewportFrame.CurrentCamera = viewportCamera

Code I have now, expected this to work but neither of the NPCs render

local clone = npc:Clone()
clone.Parent = player.PlayerGui.NPCConversation.TextButton.Frame.ViewportFrame.WorldModel
clone.PrimaryPart.Position = Vector3.new(0, 0, 0)

local viewportCamera = Instance.new("Camera")
viewportCamera.Parent = player.PlayerGui.NPCConversation
viewportCamera.CFrame = CFrame.lookAt(clone.Head.Position-Vector3.new(-0.5, 0.5, 3), clone.Head.Position-Vector3.new(0, 0.5, 0))
clone.PrimaryPart.CFrame = CFrame.lookAt(clone.PrimaryPart.Position, viewportCamera.CFrame.Position)
player.PlayerGui.NPCConversation.TextButton.Frame.ViewportFrame.CurrentCamera = viewportCamera

Try using: clone.PrimaryPart.CFrame = CFrame.identity
Instead of: clone.PrimaryPart.Position = Vector3.new(0, 0, 0)

I think this might be the issue since updating the Position property won’t update any Constraints attached to the PrimaryPart (Welds, Motor6Ds), so any parts attached to the PrimaryPart via Constraints wont follow the newly positioned PrimaryPart. Setting the CFrame property does update Constraints, causing any attached parts to move along with it.

In case you’re wondering what CFrame.identity is, its just the base CFrame with no translations or rotations applied to it, so its the equivalent of doing CFrame.new(0, 0, 0)

1 Like

put a invisible part with the correct orientation and cframe and etc in the viewport frame, then change the CFrame of both npcs to the part you put there, should work

also, do this before putting the npc’s clones in the viewportframe

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