That is a valid way to handle it but due to my specific case it isn’t really viable as far as I know.
I should probably elaborate on how the surrounding code works.
The visual handler receives a HttpService GUID, a name and an index.
The name and index are used to get the corresponding object.
The GUID is used as a tag for storage as every object needs to be assigned a unique ID so the server can send signals to the client for those effects to be moved, deleted, etc. as other methods I’ve tried have resulted in excessive lag or unreliable indexing.
After the object is cloned it checks if there’s a space in the table where a previous object was deleted and adds to that empty spot, otherwise it just adds a new index to the table. I’m doing it this way as I don’t want a table to just get unlimited new objects as that would probably break something if too many effects are spawned over a client’s lifetime on a server.
The rest of the code is pretty self-explanatory, it receives calls from the server with the GUID and some settings for how an effect object should be changed, then tries to make those changes, however the thing that breaks is trying to use :Destroy() on objects when a call for that is made, as it simply just does nothing nor even errors.
local replicatedStorage = game.ReplicatedStorage
local EffectTable = {}
local IDTable = {""}
local function DoVisualThing(ReceivedIndex:number, ReceivedMode:number, ReceivedPosition:Vector3)
if EffectTable[ReceivedIndex] ~= nil then
if ReceivedMode == 1 then
EffectTable[ReceivedIndex]:Destroy()
IDTable[ReceivedIndex] = nil
elseif ReceivedMode == 0 then
EffectTable[ReceivedIndex].Position = ReceivedPosition
end
end
end
replicatedStorage.Remotes.ReceiveVisualData.OnClientEvent:Connect(function(ReceivedIndex:string, ReceivedMode:number, ReceivedPosition:Vector3)
local IsIndexReal = table.find(IDTable, ReceivedIndex)
if IsIndexReal ~= nil then
DoVisualThing(IsIndexReal, ReceivedMode, ReceivedPosition)
else
repeat task.wait() until table.find(IDTable, ReceivedIndex)
IsIndexReal = table.find(IDTable, ReceivedIndex)
DoVisualThing(IsIndexReal, ReceivedMode, ReceivedPosition)
end
end)
replicatedStorage.Remotes.InitiateVisualEffect.OnClientEvent:Connect(function(ReceivedID:string,ReceivedName:string,ReceivedIndex:number)
local ObjectVisual
if ReceivedIndex == 0 then
ObjectVisual = game.ReplicatedStorage.VisualReplication.Projectiles:FindFirstChild(ReceivedName):Clone()
ObjectVisual.Parent = workspace.ProjectileVisuals
end
if ObjectVisual ~= nil then
local IsThereBlank = table.find(IDTable, "")
if IsThereBlank then
IDTable[IsThereBlank] = ReceivedID
else
table.insert(IDTable, ReceivedID)
end
IsThereBlank = table.find(EffectTable, nil)
if IsThereBlank then
ObjectVisual.Name = IsThereBlank
EffectTable[IsThereBlank] = ObjectVisual
else
ObjectVisual.Name = #EffectTable + 1
table.insert(EffectTable, ObjectVisual)
end
end
end)