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.

2 Likes

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?

yes, it’s still the same error, saying ‘object’ doesnt exist

If I’m not mistaken, the screenshot with the error first says off, and then prints the error. This makes sense, as when the status is off, you’re not passing along an orb variable. Is there still an error when the status is on?

1 Like

Are you sure? I suggest printing workspace:GetDescendants right after you print status to verify that the orb has indeed already been replicated.

1 Like

I just did a check and it only prints the error when the status is off, but the camerasubject still does not change to the object.


image

EDIT:

It’s fixed, I removed the print statements and changed “scriptable” to “follow” and it’s now working.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.