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)
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”)
i would like to add that this module includes a method which allows you to make the camera follow the player. it’s very easy to settup and works quite well. Highly reccomend if you have to manipulate camera a lot.