I want to prevent the player from moving their camera whilst the camera its CFrame is being set.
However when the player moves the camera, it jitters everywhere.
In the video below I’m trying to move my camera in multiple directions whilst the camera is focusing on a part. Video:
This is the localscript I use to manipulate the camera. The player activates the tool and the camera will look at a set target.
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local runService = game:GetService("RunService")
script.Parent.Activated:Connect(function()
script.Parent.RemoteEvent:FireServer(player, camera)
runService.RenderStepped:Connect(function()
camera.CFrame = CFrame.new(camera.CFrame.Position, workspace.Target.Position)
end)
end)
On another note, you should have a connection for when the tool is deactivated. That way you can stop setting the camera cframe and won’t have to deal with memory leaks.
local player = game:GetService("Players").LocalPlayer
local camera = workspace.CurrentCamera
local originalCameraType = camera.CameraType
local cameraConnection
local tool = script.Parent
local remote = tool:WaitForChild("RemoteEvent")
local runService = game:GetService("RunService")
tool.Activated:Connect(function()
--[[
remote:FireServer()
you don't need to pass the player argument because it's already passed to the server.
Also, camera objects only exist on the client so you can't pass them to the server
]]--
if (cameraConnection and cameraConnection.Connected) then return end
originalCameraType = camera.CameraType
cameraConnection = runService.RenderStepped:Connect(function()
camera.CFrame = CFrame.new(camera.CFrame.Position, workspace.Target.Position)
end)
end)
tool.Deactivated:Connect(function()
if (cameraConnection and cameraConnection.Connected) then
cameraConnection:Disconnect()
camera.CameraType = originalCameraType
end
end)