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
01 | game.Workspace.Viewportcam.CFrame = game.Workspace.Cam.CFrame.LookVector * 5 |
02 | game.StarterGui.SurfaceGui.ViewportFrame.CurrentCamera = game.Workspace.Viewportcam |
03 | game.Workspace.Viewportcam.CameraType = Enum.CameraType.Scriptable |
04 | game.Workspace.Viewportcam.CameraSubject = game.Workspace.Cam |
05 |
06 | for i,v in pairs (game.Workspace:GetDescendants()) do |
07 | if v:IsA( "BasePart" ) then |
08 | local vclone = v:Clone() |
09 | vclone.Parent = game.StarterGui.SurfaceGui.ViewportFrame |
10 | game [ "Run Service" ] .RenderStepped:Connect( function () |
11 | vclone.CFrame = v.CFrame |
12 | end ) |
13 | end |
14 | 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:
01 | game.Workspace.Viewportcam.CFrame = game.Workspace.Cam.CFrame.LookVector * 5 |
02 | game.StarterGui.SurfaceGui.ViewportFrame.CurrentCamera = game.Workspace.Viewportcam |
03 | game.Workspace.Viewportcam.CameraType = Enum.CameraType.Scriptable |
04 | game.Workspace.Viewportcam.CameraSubject = game.Workspace.Cam |
05 |
06 | for i,v in pairs (game.Workspace:GetDescendants()) do |
07 | if v:IsA( "BasePart" ) then |
08 | local vclone = v:Clone() |
09 | vclone.Parent = game.StarterGui.SurfaceGui.ViewportFrame |
10 | game [ "Run Service" ] .RenderStepped:Connect( function () |
11 | vclone.CFrame = v.CFrame |
12 | end ) |
13 | end |
14 | 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!