Set network ownership unanchored parts

I have a bunch of unanchored parts in my workspace because they are animated. I’m running a loop to get all my workspace descendants and checking if they are parts and are unanchored:

for index, eachDescendant in pairs(game.Workspace:GetDescendants()) do
    if eachDescendant:IsA("BasePart") then
        if not eachDescendant.Anchored then
            local canSet,errorReason = eachDescendant:CanSetNetworkOwnership()
            if canSet then 
                print(eachDescendant)
                eachDescendant:SetNetworkOwner(nil)
            else
                print("cannot change ", eachDescendant, " because ", errorReason)
            end
        end
    end
end

I’m wondering if anyone has a more efficient method around this as I have to loop through all my workspace descendants everytime my server starts.

Why would you run this script in the first place? The server has network ownership by default already.

Because roblox thinks it’s a good idea to make the part’s network ownership to a player when they are near.

You can make a folder/table and put models that have the unanchored parts, so the for loop doesn’t have to check all workspace’s descendants, only the folder’s descendants or table’s values (Avoiding checking unnecessary objects and parts) :wink:

1 Like

Yes actually thats a wonderful Idea and it results in a much smoother gameplay experience. Why would you need to override that and preemptively set everything to the server?

I fail to see a situation where this code would need to be used. I believe there may be a much better solution to this problem entirely.

Network ownership conflicts between multiple players.

Exploiters are able to move unanchored workspace parts around! It’s important to ensure that only servers can make these changes.