Player NetworkOwnership issue

Hello. I need to set the player’s network ownership to the server. But when I do this, I get an error that says that I cannot set the network ownership of parts that are anchored, or welded to anchored parts. But the player’s character isn’t anchored, and as far as I’m aware… it shouldn’t be welded to anything that is anchored? I could use something like a repeat task.wait() until notAnchored loop, but I’m pretty sure it is bad practice to use loops like this.

local players = game:GetService("Players")

local function setNetworkOwner(part)
	if part:IsA("BasePart") then
		part:SetNetworkOwner(nil) -- Set the network owner to the server
	end
end

local function manageCharacter(character)
	local hrp = character:FindFirstChild("HumanoidRootPart")
	if hrp then
		local hrpParent = hrp:IsDescendantOf(workspace)
		if hrpParent == false then
			repeat
				hrp.AncestryChanged:Wait()
			until hrp:IsDescendantOf(workspace)
		end
	end

	character.DescendantAdded:Connect(function(descendant) -- New parts added to the character
		setNetworkOwner(descendant)
	end)

	for _, descendant in pairs(character:GetDescendants()) do -- Existing character parts
		setNetworkOwner(descendant)
	end
end

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		manageCharacter(character) -- https://devforum.roblox.com/t/how-to-move-character-movement-to-the-server/2302307/2
		player.DevComputerMovementMode = Enum.DevComputerMovementMode.Scriptable
		player.DevTouchMovementMode = Enum.DevTouchMovementMode.Scriptable
	end)
end)

It’s possible that one of the parts in the character’s model is anchored or welded to an anchored part, and that’s why you’re seeing this error. One way to check this is to iterate through the character’s model and print out the names of any anchored parts or any parts that are welded to anchored parts.

You can try modifying your setNetworkOwner() function to check if the part is anchored or welded to an anchored part before calling SetNetworkOwner(). Here’s an example implementation:

local function setNetworkOwner(part)
	if part:IsA("BasePart") and not part.Anchored then
		local root = part:FindPartOnRay(Ray.new(part.Position, part.CFrame.LookVector * 10))
		if not root or not root:IsA("BasePart") or not root.Parent or root.Anchored then
			part:SetNetworkOwner(nil)
		end
	end
end

This implementation checks if the part is anchored and if it is, it also checks if the part is welded to another part that is anchored. If the part is not anchored and is not welded to an anchored part, it sets the network owner to nil.

3 Likes