I was trying to make a fixed camera view which track the player’s location when they moving around the room kinda like a CCTV cam
currently I manage to make swapping the camera work but the part doesn’t track the player location
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local rootPart = Character:FindFirstChild("HumanoidRootPart")
local Camera = workspace.CurrentCamera
local cameraMan = workspace:FindFirstChild("CameraMan")
local Destination = workspace:FindFirstChild("TeleportDestination")
local cctv = script.Parent.CCTV
local back = script.Parent.Return
local Looking = false
cctv.MouseButton1Click:Connect(function() -- button for CCTV cam
Looking = true
rootPart.CFrame = Destination.CFrame
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = cameraMan.CFrame
end)
while Looking == true do -- my Attempt at making the camera track the player's location
cameraMan.CFrame = CFrame.lookAt(cameraMan.Position, rootPart.Position)
end
back.MouseButton1Click:Connect(function() -- button for swap cam back
Looking = false
rootPart.CFrame = workspace:FindFirstChild("SpawnLocation").CFrame
Camera.CameraType = Enum.CameraType.Custom
Camera.CFrame = Camera.CFrame
end)
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local rootPart = Character:FindFirstChild("HumanoidRootPart")
local Camera = workspace.CurrentCamera
local cameraMan = workspace:FindFirstChild("CameraMan")
local Destination = workspace:FindFirstChild("TeleportDestination")
local cctv = script.Parent.CCTV
local back = script.Parent.Return
local Looking = false
cctv.Activated:Connect(function() -- button for CCTV cam
Looking = true
rootPart.CFrame = Destination.CFrame
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = cameraMan.CFrame
end)
game:GetService("RunService").RenderStepped:Connect(function()
if Looking then
cameraMan.CFrame = CFrame.lookAt(cameraMan.Position, rootPart.Position)
Camera.CFrame = cameraMan.CFrame
end
end)
back.Activated:Connect(function() -- button for swap cam back
Looking = false
rootPart.CFrame = workspace:FindFirstChild("SpawnLocation").CFrame
Camera.CameraType = Enum.CameraType.Custom
Camera.CFrame = Camera.CFrame
end)