Hi! I have the following snippet that finds a model called AbilityName inside a folder called Visuals in ReplicatedStorage. This snippet is in a ModuleScript in ServerScriptService that is called by another function, but I don’t believe that function is relevant to the problem at hand.
local AttackVisual = ReplicatedStorage.WeaponAssets.Visuals:FindFirstChild(AbilityName)
local UsableVisual
if AttackVisual then
local VisualModule = require(ReplicatedStorage.Modules.CombatDetails.Abilities:FindFirstChild(AbilityName))
UsableVisual = AttackVisual:Clone()
UsableVisual.Parent = workspace.AttackVisuals
Debris:AddItem(UsableVisual, VisualModule.VisualTime)
ReplicatedStorage.Events.ResponseRemotes.VisualizeAbility:FireAllClients(UsableVisual)
end
UsableVisual is a model that contains the following format:
I have a LocalScript in StarterPlayerScripts that contains the following code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local function GetVisualAbility(VisualModel)
print(VisualModel:GetChildren())
end
ReplicatedStorage.Events.ResponseRemotes.VisualizeAbility.OnClientEvent:Connect(GetVisualAbility)
Note: VisualModel = UsableVisual
I was expecting for the print statement to print the following:
[1] = Visuals,
[2] = Cast,
[3] = Hitbox
Instead I got:
[1] = Visuals
Does anyone know the reason why this is happening? I don’t think it’s Debris because the Visuals folder still returns. I tried using models instead of folders but nothing changed.
Have you tried handling the Clone() part of your code on the client instead? Perhaps this is some tricky replication problem on Roblox’s end. I usually handle effects on the client, even the parts/models getting cloned.
If it still doesn’t work then we can dig deeper.
Do not pass instances through events, as this is a recipe for lag and replication-related issues. Most specifically if the object hasn’t been replicated to the client by the time the remote reaches them, it will appear to the client as nil. Also if some of the children aren’t replicated by that time, fewer objects will be shown in the remote(as in your use case). I assume for your case this is either caused by creating said objects barely before calling the remote or due to streaming enabled.
Since objects auto-replicate to the client when placed under the right folders(workspace for example), you should ignore remotes and look for the objects directly instead. Or send a sort of “flag” through the remote instead of the actual model and then look for the model on the client(there you can use things such as WaitForChild in case lag is causing said issue).
Or, if you want to be sneaky, you can try sending a serialized instance to the client(as a string) and deserializing it to create a clone of the object on the client side. Although this will be completely client-sided, like an exploiter importing random things, there will be no way to check if your server reference of said object is the reference of the client object.
Another option is to send the path of the instance as a string(so you can analyze it on the client and run multiple WaitForChild calls to fetch the actual instance) although it may cause issues if multiple objects have the same name(there you might want to use more data points, like the object class etc).
In general, it’s better if you send simple data through remotes, and handle things like instances, effects, tweens, and such on the client.
Do not pass instances through events, as this is a recipe for lag and replication-related issues. Most specifically if the object hasn’t been replicated to the client by the time the remote reaches them, it will appear to the client as nil. Also if some of the children aren’t replicated by that time, fewer objects will be shown in the remote(as in your use case). I assume for your case this is either caused by creating said objects barely before calling the remote or due to streaming enabled.
I never knew that passing instances would cause replication-related issues, I’ve always been passing newly cloned/created instances from the server to the client and never had a problem, so I assumed there wasn’t an issue on replication
After reading your options,
Since objects auto-replicate to the client when placed under the right folders(workspace for example), you should ignore remotes and look for the objects directly instead.
This is the solution I chose to use. Rather than using a RemoteEvent that sends the model as a parameter, I used a ChildAdded event in the client that calls the function, and it seems to work well.
Thank you for your response, I learned something new today