So I was trying to delete some server-sided preload part on a client. It doesn’t seem to work because the parts refused to be destroyed.
local WhiteList = workspace:WaitForChild("WhiteListTarget"):WaitForChild("NEWMAP")
script.Parent.Activated:Connect(function()
for i,child in pairs(WhiteList:GetDescendants()) do
if child:IsA("BasePart") or child:IsA("UnionOperation") then
if not child.CanCollide and child.Transparency ~= 1 then
child:Destroy()
end
end
end
end)
No, but I have StreamingEnabled and Deferred Signal Behavior. I do have some DescendantAdded Events, but none of it is trying to set the parent of those parts.
Maybe… you meant :GetChildren() and not :GetDescendants() because it returns all the children of the parent and not the children of the objects under the parent?
Could you send me a picture of the parts you are trying to destroy and the parent too? Theres nothing wrong with the code, maybe its something to do with the logic.
Well, I’m just trying to optimize the game on performance mode by destroying useless parts that have nothing to do with gameplay. It’s the plants and the trees.
The button was for debugging. I mainly use another DescendantAdded Event to check each part to destroy since my game is StreamingEnabled, parts are only loaded when they neared.
Maybe theres objects being created and then you are trying to destroy it immediately after it being created? Try adding a wait(0) or wait(1) before destroying each object.
I think task.defer schedule the thread to run quicker than wait() or task.wait() since those makes you wait a heartbeat, and the defer is more like schedule to run at the end of the current thread.
wait() is definitely deprecated. use task.wait or task.defer