Hello,
I have a local script within a ViewportFrame as its parent. The script's code it:
local plr = game.Players.LocalPlayer local plrs = game:GetService("Players") local char = plr.Character or plr.CharacterAdded:wait() local hum = char:WaitForChild("Humanoid") local vf = script.Parent local vfc = Instance.new("Camera", vf) vf.CurrentCamera = vfc local m = Instance.new("Model", vf) m.Name = plr.Name for k,v in pairs(char:GetChildren()) do v:Clone().Parent = m end local h = m:WaitForChild("HumanoidRootPart") vfc.CFrame = CFrame.new(Vector3.new(x,y,z))
I am trying to make it clone the player's model into the ViewportFrame, which is done successfully and works since it is viewable from the ViewportFrame. However, the Camera's coordinates, see 'vfc', would have to be (0,115,25) for the camera to remotely close to the player's model, and even then it's still pretty far away.
My first question, is it possible to zoom into the player more on the ViewportFrame? And my second, if so, how and why doesn't the current system I have work?
If my code for cloning the character is incorrect too, please tell me!
~ Thank you.
Your script doesn't work because you are using x,y,z instead of 0,115,25. But let's not do this.
Trying to set a viewport camera's cframe exactly can be pretty tricky considering we cant see the workspace of the viewport frame fully.
Instead, lets set it relative to the character to that we don't have to deal with exact numbers.
local plr = game.Players.LocalPlayer local plrs = game:GetService("Players") local char = plr.Character or plr.CharacterAdded:wait() local hum = char:WaitForChild("Humanoid") local vf = script.Parent local vfc = Instance.new("Camera", vf) vf.CurrentCamera = vfc local m = Instance.new("Model", vf) m.Name = plr.Name for k,v in pairs(char:GetChildren()) do v:Clone().Parent = m end local h = m:WaitForChild("HumanoidRootPart") vfc.CFrame = m.HumanoidRootPart.CFrame*CFrame.new(0,0,10)
Now the character will be right in the middle of the screen and you can modify the *CFrame.new() to offset it to your desire.