Hi, I’m making a ragdoll script right now, and I’m having a problem with setnetworkownership.
Here’s the code:
self.Character.HumanoidRootPart:SetNetworkOwner(nil)
self.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
task.wait()
for _, v in self.Character:GetDescendants() do
if v:IsA("Motor6D") then
local att0, att1 = Instance.new("Attachment"), Instance.new("Attachment")
att0.CFrame = v.C0
att1.CFrame = v.C1
att0.Parent = v.Part0
att1.Parent = v.Part1
local ballSocketConstraint = Instance.new("BallSocketConstraint")
ballSocketConstraint.Name = "__RAGDOLLCONSTRAINT"
ballSocketConstraint.Attachment0 = att0
ballSocketConstraint.Attachment1 = att1
ballSocketConstraint.Parent = v.Part1
v.Enabled = false
end
end
The first two lines work as intended, I know that, but after I ragdoll (after the task.wait()) it for some reason undos the ownership and humanoid state, and goes back to normal.
Why is this happening? Everything works before I ragdoll the character.
I would recommend setting the network owner of each baseparts within the character. You can utilize GetChildren() or GetDescendants(), whichever fits your needs best, and within that table address each basepart and use SetNetworkOwner(nil) to give the server the ownership. However, this may not solve your issue without seeing the rest of the code. Make sure the character is fully loaded before trying to do this. You can use Player.CharacterAppearanceLoaded() to ensure character parts have fully loaded (if this is a player’s character and not an NPC)
Example code:
local Character = self.Character --//(? Self may not be needed depending on use, but make sure character is addressed properly)
for i,v in pairs(Character:GetChildren()) do
if v:IsA("BasePart") and v:CanSetNetworkOwnership() then else continue end
v:SetNetworkOwner(nil)
end
--//Rest of code here
The character is definitely fully loaded, and I already tried setting all the BaseParts, it’s fine though, I already got it working. I just switched the order of the code. I ragdolled then set the ownership.