Hello I am trying to do a viewport frame script. The problem is when i'm using a CFrame for a camera for the viewport frame this happens
14:28:09.213 - game.Workspace.Viewportcam.CFrame = game.Workspace.Cam.CFrame.LookVector:1: invalid argument #3 (CFrame expected, got Vector3) 14:28:09.215 - Stack Begin 14:28:09.225 - Script 'game.Workspace.Viewportcam.CFrame = game.Workspace.Cam.CFrame.LookVector', Line 1 14:28:09.227 - Stack End
What I want to achieve is there is a part above the viewport frame that the camera will face In front of. Now I actually do know that look vector is meant for vector3 but is there a way to use it in a CFrame? Here is the code
game.Workspace.Viewportcam.CFrame = game.Workspace.Cam.CFrame.LookVector * 5 game.StarterGui.SurfaceGui.ViewportFrame.CurrentCamera = game.Workspace.Viewportcam game.Workspace.Viewportcam.CameraType = Enum.CameraType.Scriptable game.Workspace.Viewportcam.CameraSubject = game.Workspace.Cam for i,v in pairs(game.Workspace:GetDescendants()) do if v:IsA("BasePart") then local vclone = v:Clone() vclone.Parent = game.StarterGui.SurfaceGui.ViewportFrame game["Run Service"].RenderStepped:Connect(function() vclone.CFrame = v.CFrame end) end end
For some more info
The local script is in replicated first
Camera is in workspace
Gui is a SurfaceGui (I could use billboard but I want to use surfacegui for this case.)
But in advance thanks!
In your script as follows:
game.Workspace.Viewportcam.CFrame = game.Workspace.Cam.CFrame.LookVector * 5 game.StarterGui.SurfaceGui.ViewportFrame.CurrentCamera = game.Workspace.Viewportcam game.Workspace.Viewportcam.CameraType = Enum.CameraType.Scriptable game.Workspace.Viewportcam.CameraSubject = game.Workspace.Cam for i,v in pairs(game.Workspace:GetDescendants()) do if v:IsA("BasePart") then local vclone = v:Clone() vclone.Parent = game.StarterGui.SurfaceGui.ViewportFrame game["Run Service"].RenderStepped:Connect(function() vclone.CFrame = v.CFrame end) end end
i would change the 1st line from
game.Workspace.Viewportcam.CFrame = game.Workspace.Cam.CFrame.LookVector * 5
To
game.Workspace.Viewportcam.CFrame = game.Workspace.Cam.CFrame * CFrame.new(game.Workspace.Cam.CFrame.LookVector * 5)
as you was converting the Cframe of the camera part to a Vector3 so i've modified the line so it puts the camera 5 studs away from your camera brick according to its LookVector
As for the rest of your script, it looks good!
Hope this helps!