What do you want to achieve?
Make the camera smooth at tracking the player
What is the issue?
The camera is extremely laggy when following the players position
What solutions have you tried so far?
None
I am trying to make a camera system for my game where it follows the player on the X axis but it is extremely laggy and I don’t know how to make it smooth.
TrackPlayer Script:
trackingPlayer = nil
wait(3)
for i, player in pairs(game.Players:GetChildren()) do
trackingPlayer = player
end
while wait() do
repeat wait() until trackingPlayer ~= nil
script.Parent.Position = Vector3.new(trackingPlayer.Character.HumanoidRootPart.Position.X, script.Parent.Position.Y, script.Parent.Position.Z)
end
CameraScript LocalScript:
local CameraPart = workspace.CameraPart
local CurrentCamera = workspace.CurrentCamera
repeat wait()
CurrentCamera.CameraType = Enum.CameraType.Scriptable
until CurrentCamera.CameraType == Enum.CameraType.Scriptable
while wait() do
CurrentCamera.CFrame = CameraPart.CFrame
end
--//Services
local RunService = game:GetService("RunService")
--//Variables
local CameraPart = workspace.CameraPart
local CurrentCamera = workspace.CurrentCamera
--//Functions
repeat task.wait()
CurrentCamera.CameraType = Enum.CameraType.Scriptable
until CurrentCamera.CameraType == Enum.CameraType.Scriptable
RunService.RenderStepped:Connect(function()
CurrentCamera.CFrame = CameraPart.CFrame
end)
And your TrackPlayer Script to this:
--//Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
--//Variables
local Part = script.Parent
local Vector3New = Vector3.new
--//Controls
local trackingPlayer = nil
--//Functions
task.wait(3)
for i, player in ipairs(Players:GetPlayers()) do
trackingPlayer = player
end
RunService.Stepped:Connect(function()
Part.Position = Vector3New(trackingPlayer.Character.HumanoidRootPart.Position.X, Part.Position.Y, Part.Position.Z)
end)