Just like the title says, I’m trying to make my scriptable camera follow player but for some reason couldn’t. Here’s the code for my scriptable camera:
local RepStore = game:GetService("ReplicatedStorage")
local ChangePRemote = RepStore.changePerspective
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local function ChangeP(follow)
print(follow)
camera.CameraType = Enum.CameraType.Scriptable
local char = player.Character
local humroot = char:FindFirstChild("HumanoidRootPart")
local pos = humroot.Position
local endpos = pos + Vector3.new(10,50,0)
player.CameraMinZoomDistance = 25
camera.CFrame = CFrame.lookAt(endpos, pos)
camera.CameraSubject = humroot
end
ChangePRemote.OnClientEvent:Connect(ChangeP)
What should I add to achieve that goal?
FYI, the “follow” argument in the function is unrelated to my question.
if you want the camera to follow the player, Use BindToRenderStep. If it doesn’t work , try to make the CameraType Custom
(with BindToRenderStep).
1 Like
I did it like this:
local RunService = game:GetService("RunService")
local RepStore = game:GetService("ReplicatedStorage")
local ChangePRemote = RepStore.changePerspective
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local function ChangeP(follow)
print(follow)
camera.CameraType = Enum.CameraType.Scriptable
local char = player.Character
local humroot = char:FindFirstChild("HumanoidRootPart")
local pos = humroot.Position
local endpos = pos + Vector3.new(10,50,0)
player.CameraMinZoomDistance = 25
camera.CFrame = CFrame.lookAt(endpos, pos)
camera.CameraSubject = humroot
end
local function RunFunc(follow)
RunService:BindToRenderStep(follow, 1, ChangeP)
end
ChangePRemote.OnClientEvent:Connect(RunFunc)
It works so far, but would this cause performance issues?
As far as you don’t call the remote event more than 1 time, no. If you need the event to be fired multiple times, you could use the UnBinbFromRenderStep, to stop the camera or do whatever you want when you want it to stop, so that the Bind doesn’t repeat more than once and doesn’t cause lag.
Also to reduce lag you could set the variables:
local char = player.Character
local humroot = char:FindFirstChild(“HumanoidRootPart”)
Outside of the function.
There is a rather simple solution to this.
Instead of touching RunService, you can use the Camera object itself and adjust its CameraType to “Fixed”
It will stop Camera movement and also track the player.