Remote Function Receiving Nil for an Argument

On server side, I have an OOP object invoking a remote function. I’m having some trouble sending a prismatic constraint to the client side recipient.

function Class:Play()
    local player = self.Player -- Player object for player argument of InvokeClient

    if not pcall(function()
        ScaleTransformation:InvokeClient(player, self.Constraint)
    end) then
		-- Future error handling goes here
	end

    return
end

self.Constraint is instantiated when I create the OOP object, though some rudimentary testing makes me think that it is being replicated properly across the server-client boundary. It even shows up in the outliner while I’m playtesting in client view. Following that logic, I don’t think self.Constraint being a non-replicated instance would be a problem for the remote function.

Unless I misunderstand how passing instances work, I don’t think a prismatic constraint is a table either, so all the other argument limitations of remote functions shouldn’t be a problem either.

With these reasonings, I’m not entirely sure what else to check to figure out why self.Constraint is being passed as nil. What else could be stopping my prismatic constraint from being passed through the remote function?

1 Like

Has your prismatic constraint loaded on the server before sending it to the client

1 Like

Is being loaded on server-side different from being in the outliner or being able to be printed out through a logpoint? self.Constraint is instantiated when the OOP object is created, so I’d imagine that it’s loaded before Play is ever called.

1 Like

im pretty sure its after Play is called but try printing the self.constraint to check it exists first on the server

1 Like

Yep. It’s there:

It might not be in the picture, but the highlighted line is in the Play method.

Additionally, while typing this out, I thought it might be the target:SetNetworkOwner(player) line, but commenting that out and running it again yields no difference (ie. the prismatic constraint still passes as nil).

instead of passing the constraint try sending the metatable in the remotefunction.

I interpreted that as just sending self. So I did and the constraint still didn’t go through.

That said, I did find something interesting. When I passed the metatable through and looked at it through the watch window, the only instance variables that made it through were objects that were parented to another object I created using another instance constructor. To put it in more technical terms, this is the general layout of the constructor for my OOP object looks like:

function Class.new(normalPart) -- Superclass constructor
    local object = setmetatable({}, Class)

    object.NormalPart = normalPart -- A part that existed before the OOP object

    object.ConstructedPart = Instance.new("Part")
    object.ConstructedPart.Parent = workspace

    object.Constraint = Instance.new("PrismaticConstraint")
    object.Constraint.Parent = object.ConstructedPart

    return object
end

So maybe the problem lies there? Or am I completely misguided?

Turns out it was the fact that it wasn’t loaded on the client side. I tested this by adding a delay between instantiating my OOP object and calling its Play method and it worked. I’ll do a bit more refining so I’m not relying on a timer to let the constraint replicate though.

Cool so it was the delay between the server and client