So I am trying to make viewport frame that renders player’s character, but the character wont show up in the frame. But let me say something funny, when I manually in game take the model out of the frame, and then put it back, the character shows up! I don’t know why is it happening so any help will be appriciated!
I don’t get any error in output btw
video of “funny thing”:
My script:
repeat task.wait(0.5) until game:IsLoaded()
local players = game:GetService("Players")
local replicated = game:GetService("ReplicatedStorage")
local plr = players.LocalPlayer
local function setUpViewports()
PlayerOneVPF = Instance.new("ViewportFrame")
PlayerOneVPF.Parent = script.Parent
local aspectRatio = Instance.new("UIAspectRatioConstraint")
aspectRatio.Parent = PlayerOneVPF
aspectRatio.AspectRatio = 1
aspectRatio.AspectType = Enum.AspectType.FitWithinMaxSize
PlayerOneVPF.Size = UDim2.new(0.1,0,1,0)
PlayerOneVPF.Position = UDim2.new(0,0,0,0)
PlayerOneVPFCamera = Instance.new("Camera")
PlayerOneVPFCamera.Parent = PlayerOneVPF
PlayerOneVPF.CurrentCamera = PlayerOneVPFCamera
end
setUpViewports()
local plr1VPchar = nil
local plr2VPchar = nil
local function spawnCharactersToFrames(plr1, plr2)
plr1.Character.Archivable = true
local NpcToCopy = plr1.Character:Clone()
NpcToCopy.Parent = PlayerOneVPF
NpcToCopy.PrimaryPart.Position = Vector3.new(0,0,0)
plr1VPchar = NpcToCopy
local part = Instance.new("Part") --I rendered part here just to be sure the frame is working properly
part.Parent = PlayerOneVPF
PlayerOneVPFCamera.CFrame = CFrame.new(Vector3.new(0, 2, 12), part.Position)
end
spawnCharactersToFrames(plr)
Try putting the character inside a WorldModel, inside the ViewportFrame. This will keep the frame updated to always show what is inside. Without a WorldModel, it only renders the content inside once.
Try having a script set the current camera of that viewport frame to a new camera on runtime. If that doesn’t work, I guess you could just have the script parent the character to the viewport frame twice, so it has to load.
The camera is already being assigned in script on runtime. I was sending screenshots from running game. And I just tried parenting it twice, but still no difference. I am kinda sure there is nothing wrong with the camera, since when I create part and parent it into the viewportframe, it renders as it should. So there must be something wrong with the character.
Is the character in the correct position when placed in the world model? I’m pretty sure physics doesn’t exist in viewport frames, but I could be wrong. So maybe when you put the character in the workspace, it falls in the correct position when you put it back in the frame.
Yes, I set the character’s pivot to 0,0,0 and I am having the camera to look at those coordinates. And you are indeed right that there are not physics in viewport.
I don’t really remember what the issue was, but looking back at my script, I am pretty sure it was because my character wasn’t actually at the right coordinates, as I used .Position property of the primary part, which doesn’t move the character body welds appropriately.
So all I can suggest now is if you’re also setting the Position property, to instead use either CFrame or :PivotTo() on the model.
Also make sure your camera is set properly in the viewport, as it can sometimes get “unset” when you start the game.
Sorry I couldn’t be more of a help.
Edit: I checked the video I had added previously and it seems both the camera and positions are set correctly, I’m gonna try to find the archived place and update this when I’ll find out the issue.
Edit 2: I’ve looked into it and it seems the issue is really the .Position setting, why I got confused is because when I was watching the video, the properties said that the origin position is 0,0,0 which was true for the primary part (humanoidRootPart), however the welded parts (body parts) have not moved accordingly with it, and when you change the parent property to workspace, the welds recalculate, “fixing” the model and putting all of the bodyparts to the correct position around the PrimaryPart.
In short, try to use :PivotTo() function onto the character model to set its position to the correct coordinates. Other than that, I cannot help you