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:
01 | function CheckWelds(Part) |
02 | local Found = false |
03 | for i,v in pairs (Part:GetDescendants()) do |
04 | if Found = = false then |
05 | if v.ClassName = = "Weld" then |
06 | Found = true |
07 | return "Found" |
08 | end |
09 | end |
10 | end |
11 | if Found = = false then |
12 | wait() |
13 | return "None" |
14 | end |
15 | end |
I fixed it with a pcall function. ::::))))))
1 | pcall ( function () |
2 | v:SetNetworkOwner( nil ) |
3 | 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:
1 | for _,v in pairs (workspace:GetDescendants()) do |
2 | if v:IsA( "BasePart" ) then |
3 | if not v.Anchored and #v:GetJoints() = = 0 then |
4 | v:SetNetworkOwner( nil ) |
5 | end |
6 | end |
7 | end |