Yup, exactly!
Please keep in mind that if you have, say, an Instance ReplicatedStorage.X
, and you set X.parent = ServerStorage
on the Server, then the Server will replicate X.parent = nil
to the Client, so you have to be ready for that.
Yup, exactly!
Please keep in mind that if you have, say, an Instance ReplicatedStorage.X
, and you set X.parent = ServerStorage
on the Server, then the Server will replicate X.parent = nil
to the Client, so you have to be ready for that.
I assume those who clone parts they need like ReplicatedStorage.X:Clone()
would have a detached instance? So cleanup on X in replicated storage wouldnât affect the copies of X made on the client? Only direct references would be affected?
That sounds a little spooky so I might opt for the cloning method for a clean detachment. Thanks for the tips!
Yes, exactly! Clones are totally separate instances from the original.
Hey, Iâd like to know how exactly does the Debris:AddItem()
keeps track of the lifetime? does it simply use the deprecated wait
or delay
function?
so would something like this task.delay(1, game.Destroy, instance)
be a better alternative? assuming that weâre sure that instance exists
If you want predictable timing you should very much be using something like task.delay
. The contract of the Debris
service is that it may Destroy
any number of things you give it earlier than the specified delay in order to maintain the performance level of the game. I.e.: âCleaning up debrisâ.
Being an old service from way back in the early days of Roblox, it actually uses an entirely different mechanism than either delay
or task.delay
.
This is incredibly important advice and should really be documented somewhere.
Will there ever be a way to schedule a namecall directly, without the overhead of wrapping it in a Lua function? task.delay(1, instance.Destroy, instance)
feels very bad.
Thatâs not accurate at all, in fact, thatâs the old way of checking and detecting when an object got destroyed. If you create a new Instance, it will be parented to nil by default, we cannot assume that the object is destroyed because is parented to nil. For example:
local Part = Instance.new("Part")
if Part.Parent == nil then
print("Is destroyed!") --> This is really inaccurate.
end
Part.Parent = workspace
Part.Parent = nil
if Part.Parent == nil then
print("Is destroyed!") --> This is really inaccurate, the part is not destroyed at all, it was just removed from workspace and parented to nil.
end
Part.Parent = workspace
For this reason, I said we needed a property that sets to true when we call Destroy.
Maybe far in the future. We gave this some though when working on the task
library and thereâs no great way to do it without special Luau specific syntax so if this does come it will come alongside some significant larger Luau feature.
Could you elaborate on why this is? Does the namecall optimization only work when the call site is generated by the Luau compiler? Or do you just mean a generic way to convert a ânamecall methodâ into a closure that can be spawned normally through task
(without incurring the cost of __index
)?
Is there a difference between âremovedâ and âdestroyed,â because if it is removed on the client, than it would be doing its job, right?
Destroyed means you canât parent it back to the game, removed means you can.
Here,
destroyed means parent = nil, parent gets locked, connections get cleaned up
removed means parent = nil
so the difference is that if you just remove an Instance, i.e. set itâs parent
to nil
, all of its connections are still there, and the parent is not locked so you can reparent it down the line.
Documentation for Destroy() here: Instance:Destroy
Oh, so if its parent is nil than it didnât appear anywhere on screen or in game right?
If an Instanceâs parent is nil, then you wonât see it in the game. It could still influence what you see in the game though, via connections it may have.
Sorry if this was already asked butâŚ
Server Workspace
â Folder X --> Server Script destroys this
â Folder Y
Client Workspace
â Folder X
â Folder Y
â Part Z --> A LocalScript has created this
What happens to Part Z? You say it wonât be destroyed, so does that mean it will exist despite its parent being nil
? What if I donât handle Folder Y with Destroying
to cleanup Part Z?
Please read the post fully before you said that.
Yes, it still exists even though the parent is nil because it didnât lock the parent property.
If you donât handle Folder Y to cleanup Part Z, the same thing I said just now.