Because I need to perform disconnections client side before the destroy is replicated.
I’ve run some tests, and if the wait time is short (a few frames), the event handler might still run afterward.
If I wait something like 1 second, there shouldn’t be any problems? Or is this considered bad practice?
Am i misunderstanding something?
He wants the client to know that the object is being destroyed so that he can clean up some connections beforehand. In that case .Destroying absolutely works through boundary.
I have issues with Destroying or AncestryChanged due to deferred behaviour. When this events are run, the object is already destroyed which could be problematic. short exemple to demonstrate the issue
Server
local testModel = workspace.testModel
local RemoteEvent = testModel.RemoteEvent
task.wait(10)
for i = 1,10 do
task.wait()
RemoteEvent:FireAllClients(i)
end
testModel:Destroy()
client
local RunService = game:GetService("RunService")
local testModel = workspace:WaitForChild("testModel")
local RemoteEvent = testModel.RemoteEvent
connection = RemoteEvent.OnClientEvent:Connect(function(i)
print(i, RemoteEvent.Parent)
end)
testModel.Destroying:Connect(function()
connection:Disconnect()
end)
Whatever method i use, i have no choice to delay the Destroy() call. Or do additional checks in my code. I fell like deferred behaviour make coding way more complicated now…