Now I am noticing some errors in my scripts. One being where I am creating a part via Instance.new on the server, then firing to client that part as an argument for the client to pick up and do effects visually on the client.
But now an error occurs claiming that part is ‘nil’ on the client.
I figured it may be because i toggled streaming enabled recently.
Hey. This is not a bug, but a functionality.
Let me explain: The instance is nil because it hasn’t been replicated to the client from the server due to some reasons, one could be that your client is just far away and cannot see the instance, so server won’t replicate it.
By enabling Streaming you’re going through one more step when player joins the server. If you’re sending an Instance when player joins the game, it probably won’t work since the server has not replicated the instance yet.
Either you could set the instance to always replicate ignoring streaming rules, or you handle the error on client checking if Instance exists.
I recommend reading how Content Streaming works.
Why do you need streaming enabled?
And what is exact use case you need to do with creating instance and then right away sending an event?
Instead of sending the instance you can send it’s name or path, so client can use WaitForChild, if you’re sure that the instance will be streamed in after creation. There are some ways how to solve it.
game.ReplicatedStorage.Events.Client.OnClientEvent(function(arg, model)
if arg == "FloorSmashEffect" then
....
Character.PrimaryPart.Position = model.Position
--Errors here saying model is nil
end
end)
You need to check if model exists on the client before running anything. I recommend looking into using CollectionService:GetInstanceAddedSignal for visual effects on the client with streaming enabled though as that’s what my game does and it works pretty well for me.
If you’re asking about GetInstanceAdded it’s something that’s useful for streaming enabled related client side stuff. Whenever a part is rendered that has a certain CollectionServiceTag if the tag matches the tag the function is listening for it will run that function. If your asking about the model thing you can just check if the model == nil on the client and if it does than return end.