Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i set all parts NetworkOwner to nil in the workspace?

Asked by 3 years ago

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

https://www.youtube.com/watch?v=dQw4w9WgXcQ&ab

2 answers

Log in to vote
0
Answered by 3 years ago

I fixed it with a pcall function. ::::))))))

pcall(function()
v:SetNetworkOwner(nil)
end)
0
A pcall will stop your script from returning the error, it'll still error inside the pcall, so it still won't work. Befogs 113 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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

Answer this question