Why is the instance im sending through a remote returning nil?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to send a part from the server to client

  2. What is the issue? Include screenshots / videos if possible!
    the part is returning nil on the client

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    searching on the dev forum but nothing worked

Server:

local repStorage = game:GetService("ReplicatedStorage")

local remoteEventsFold = repStorage:WaitForChild("RemoteEvents")
local changeCamEvent = remoteEventsFold:WaitForChild("ChangeCamRE")

local shackFold = game.Workspace:WaitForChild("Shack")
local camPosFold = shackFold:WaitForChild("CamerasPos")

local deskCam = camPosFold:WaitForChild("DeskCam")

local function setUp(plr)
	print("hi")
	changeCamEvent:FireClient(plr, deskCam)
end

game.Players.PlayerAdded:Connect(function(plr)
	setUp(plr)
end)

Client:

local plr = game:GetService("Players").LocalPlayer

local repStorage = game:GetService("ReplicatedStorage")

local remoteEventsFold = repStorage:WaitForChild("RemoteEvents")
local changeCamEvent = remoteEventsFold:WaitForChild("ChangeCamRE")

local cam = game.Workspace.CurrentCamera

changeCamEvent.OnClientEvent:Connect(function(deskCam)
	print(deskCam)
	cam.CameraType = Enum.CameraType.Scriptable
	cam.CFrame = deskCam.CFrame
end)

The instance hasn’t replicated to the client by the time the remote is received. Therefore it shows up as nil to them. When you send an instance through a remote you basically send the reference to it, if the client can’t find it its nil.

2 Likes

Oh yea lmao, this was the problem. I just added a wait.

In general it’s a bad practice, there’s room for error. It’s far better if you just use a WaitForChild on the client.

1 Like

Alright then, thank you for the help.

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