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)
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.
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
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?