Can't set the CameraSubject?

I am trying to set the camera subject to a part in workspace, however it isn’t working at all.

Relevant parts of the server script:

local Orb = game:GetService("ServerStorage"):WaitForChild("Storage"):WaitForChild("VitalisSummon")
local orb = Orb:Clone()
orb.Parent = workspace

game.ReplicatedStorage.Events.SummonCamera:FireClient(vitalis, "on", orb) -- vitalis = player, "on" = status, orb = the part

wait(5)
game.ReplicatedStorage.Events.SummonCamera:FireClient(vitalis, "off")

Local Script:

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("SummonCamera").OnClientEvent:Connect(function(status, object)
	print(status) -- this will print "on" when i fire the event
	print(object.Parent.Name) -- this always errors, i tried object.Name and it said nil, this also says nil.
	if status == "on" then
		camera.CameraType = Enum.CameraType.Follow -- the camera type DOES change
		camera.CameraSubject = object -- it just does not set the subject to the object.
	else
		camera.CameraType = Enum.CameraType.Custom -- this works when i fire the "off" status
		camera.CameraSubject = player.Character.Humanoid -- this works when i fire the "off" status
	end
end)

The object DOES exist, and its parented to workspace, and it’s being fired through the event, so I don’t know why its not being picked up…?
image

Sounds like object is nil because of the replication delay from server to client. When you clone the object on the server it exists immediately, however it takes some amount of time to be replicated to each client (and may never replicate depending on the streaming radius). See Instance Streaming: Timing Delay for more info.

1 Like

Just use camerautil. It has everything u need.

around 10 lines of code run before the event is fired, so i dont think it would be that

The number of lines that run before an event is fired has nothing to do with replication delay of instances. You could likely confirm this is your issue by adding a manual wait in the server script:

local Orb = game:GetService("ServerStorage"):WaitForChild("Storage"):WaitForChild("VitalisSummon")
local orb = Orb:Clone()
orb.Parent = workspace

task.wait(2) --This is not a fix, just a test to confirm replication delay is the issue

game.ReplicatedStorage.Events.SummonCamera:FireClient(vitalis, "on", orb) -- vitalis = player, "on" = status, orb = the part
1 Like

I added the wait and it made no difference, the camerasubject still didn’t change

Are you still getting the error about a nil index?