I am trying to send a model from the server to a client using RemoteFunction and InsertService. However, when returning the model to the client, the model turns NIL.
Anyone has any idea what I’m doing wrong, or if this is a common thing?
Local Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local modelId = randomModelID
local remoteFunction = ReplicatedStorage:WaitForChild("RemoteFunction")
local model = remoteFunction:InvokeServer(modelId)
print(typeof(model)) -- Returns nil
model.Parent = ReplicatedStorage -- Returns error: attempt to index nil with 'Parent'
Server Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local InsertService = game:GetService("InsertService")
local remoteFunction = ReplicatedStorage:WaitForChild("RemoteFunction")
local function returnModel(_, modelId)
local model = InsertService:LoadAsset(modelId)
print(typeof(model)) -- Returns as "Instance"
return model
end
remoteFunction.OnServerInvoke = returnModel
I thought this way would work the same as placing it in ReplicatedStorage. Anyways, I don’t want it to go through any other players, I just want the specific client to receive the model.
Unfortunately, Roblox doesn’t give tools for only a single client to see the object, so you would have to let every client see it. Though, what you do with the model in particular can be client specific.
That may actually work; I didn’t think about that. Wish there was a better way though.
Oh. That’s quite unhandy. Since I’m working with big models, having them go through every single client makes it quite unefficient. It’s weird that you can basically send anything to the client using remoteEvents or remoteFunctions, but somehow objects need to be replicated to every single client.