Can I pass an animation instance to the client through a remove event?

I am trying to send an animation object from the server to the client, through a remote function, however, I keep getting nil on the client.

Is this even possible?

**Server Side…
ClientFunc:InvokeClient(player,id,message,data)

**Client Side…
function onRemoteFunc(id, message, data)
print(data)
end
ClientFunc.OnClientInvoke = onRemoteFunc

1 Like

I would assume NO, except for this excerpt from the api…

Where it says …

Parameters

Any type of Roblox object (Enumeration value, instance, userdata) can be passed as a parameter in a RemoteEvent firing or RemoteFunction invocation. Lua types (such as numbers, strings, boolean) can also be passed, although there there are some limitations on how data can be passed.

If data is nil, what was data before you passed it in?

it was an animation instance
if I use a print, just before I send, it prints the contents of data as ‘Animation’
if I do a print just after receiving on the client, it prints the contents of data as nil

Is the instance parented to something non-nil? While unparented or parented to nil, the instance won’t replicate to the client so the client will receive the object as nil.

It is parented to game.ServerStorage

Do you really think the parenting could be the issue?

Yes, this is the issue.

Instances aren’t sent over the network, the reference to them is. The client doesn’t have access to ServerStorage, therefore the reference to the animation is nil (game → ServerStorage → Animation).

Placing the animation in a service which the client can access (such as ReplicatedStorage) would resolve your issue.

I’m not sure why your game relies on this behaviour though. Surely there is a better way. Animations for players should typically be run from their client, which then replicates to the server. This means there’s no additional networking involved, so no latency for the player. I’m not sure why the server is involved and sends a reference to the animation here at all. I recommend you try to improve this logic, it’ll save you a lot of pain and troubleshooting in the future.

5 Likes

Its not necessary to send the animation to the client, considering I send the animation id, and just create the animation instance client side.
However, on certain occasions (especially with custom models, that are local, and not published to robox) a client might need an instance of something, out of a pool of objects that you would not want ALL of the instances stored in client memory.

Thanks for the info.