I want to make a script that sets NetworkOwner to nil for all parts in workspace but it gives this error: Network Ownership API cannot be called on Anchored parts or parts welded to Anchored parts.
So i tried to fix it but it still gives a error. The Code:
function CheckWelds(Part) local Found = false for i,v in pairs(Part:GetDescendants()) do if Found == false then if v.ClassName == "Weld" then Found = true return "Found" end end end if Found == false then wait() return "None" end end for i,v in pairs(workspace:GetDescendants()) do if v:IsA("BasePart") and not v:IsA("Terrain") then if v.Anchored == false then local Welds = CheckWelds(v) if Welds == "None" then print("yes") v:SetNetworkOwner(nil) end end end end
I fixed it with a pcall function. ::::))))))
pcall(function() v:SetNetworkOwner(nil) end)
Because a part doesn't have a weld as a child, doesn't mean it isn't welded. You can check if its welded to anything with #Part:GetJoints(), if its 0 that means there are no welds attached. So your whole code is just this now:
for _,v in pairs(workspace:GetDescendants()) do if v:IsA("BasePart") then if not v.Anchored and #v:GetJoints() == 0 then v:SetNetworkOwner(nil) end end end