I am trying to use the viewport frame. I got the viewport frame in the screen gui on the side of the screen. The issue I am having is that the camera view of the player is in the same spot view of the viewport frame.
game:GetService("Workspace")
local cam = workspace.CurrentCamera
local pic = workspace.pic
local view = script.Parent.ViewportFrame
game:GetService("RunService").Heartbeat:Connect(function(run)
cam.CFrame = pic.CFrame
cam.CameraType = Enum.CameraType.Scriptable
cam.FieldOfView = 70
cam.CameraSubject = pic
view.CurrentCamera = cam
for i, child in pairs(workspace:GetChildren()) do
if not child:IsA("Terrain") and not child:IsA("Camera") and child ~= pic then
child.Archivable = true
local clone = child:Clone()
clone.Parent = view
end
end
end)
when using CameraType as Scriptable you will have to update the CFrame manually or thats what i think it is just Try Setting the CameraType to Enum.CameraType.Custom
And set the CameraSubject to the part you want to follow
Hi, there thank you for the reply.
I changed the camera type to custom
Cam.CameraType = Enum.CameraType.Custom
What do you mean by setting the part I want to follow I think I already got it in the script. Is this part your meaning because pic is the part I want it to follow??
local Players,Player = game:GetService("Players"),game:GetService("Players").LocalPlayer
local Viewport = Player.PlayerGui.vGui.ViewportFrame
local SteppedConnection
function FollowCamera(Camera:Camera?, Humanoid:Humanoid?, hrp:BasePart?)
Camera.CameraSubject = Humanoid
Camera.CameraType = Enum.CameraType.Scriptable
SteppedConnection = Run.Stepped:Connect(function()
Camera.CFrame = CFrame.lookAt(hrp.Position + Vector3.new(0, 0, 5), hrp.Position)
end)
end
function CreateStuff()
local DummyHumanoid = Players:CreateHumanoidModelFromUserId(Player.UserId)
local vCamera = Instance.new("Camera")
DummyHumanoid.Name = Player.Name
Viewport.CurrentCamera = vCamera
DummyHumanoid.Parent = Viewport.WorldModel
vCamera.Parent = Viewport
FollowCamera(vCamera, DummyHumanoid.Humanoid, DummyHumanoid.PrimaryPart)
end
function Cleanup()
SteppedConnection:Disconnect()
for _,v in Viewport:GetDescendants() do
if not v:IsA("WorldModel") then
v:Destroy()
end
end
end
CreateStuff()
local workspace = game:GetService("Workspace")
local pic = workspace.pic
local view = script.Parent.ViewportFrame
-- Create a new camera for the viewport frame
local viewportCamera = Instance.new("Camera")
viewportCamera.Parent = view
view.CurrentCamera = viewportCamera
game:GetService("RunService").Heartbeat:Connect(function(run)
-- Set the viewport camera to look at the 'pic' object
viewportCamera.CFrame = pic.CFrame
for i, child in pairs(workspace:GetChildren()) do
if not child:IsA("Terrain") and not child:IsA("Camera") and child ~= pic then
child.Archivable = true
local clone = child:Clone()
clone.Parent = view
end
end
end)