Motor6D being Parented to Nil

I have this below script, but the Motor6D keeps disappearing. On the second print, it print’s “nil” but the first one prints the parent I set it to.

game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local M6D = Instance.new("Motor6D",Character:WaitForChild("UpperTorso"))
		print("M6D Attached! Its parent is "..M6D.Parent:GetFullName())
		wait(10)
		print(M6D.Parent.Name)
	end)
end)

I’ve tried setting the parent to different things and messing with the Motor6D settings, and I found that it didn’t disappear when I set its parent to HumanoidRootPart. What? Why? (I’d prefer the parent was something else, so I don’t want this to be my solution yet.)
I then tested manually adding a Motor6D into a dummy and running the game, and it was just fine…
The Motor6D might be getting disconnected somehow, even though it’s not being welded to anything.
I searched before posting.

1 Like

Wait for the character’s parent to be changed. I don’t know what goes on just as the character is being loaded, but it is probably something that destroys your weld.

game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Character.AncestryChanged:Wait()
		
		local M6D = Instance.new("Motor6D",Character:WaitForChild("UpperTorso"))
		print("M6D Attached! Its parent is "..M6D.Parent:GetFullName())
		wait(10)
		print(M6D.Parent.Name)
	end)
end)
1 Like

That worked, but I would like an explanation on how that worked??? How does waiting for the Character’s parent to switch change anything?

To be honest, I don’t know.

I think when the character is instanced there is something internally is being that breaks the weld, like an internal call of :BreakJoints. I really do not know.

Where did you hear to try to do that? Maybe there’s an explanation there? If you’re the one who made it and don’t know how it works, that might be a risk of inconsistency.

I just tried it and it worked. :man_shrugging:

I already knew that, but how? It could be inconsistent like I said. There is probably a better alternative.

when instance connected to contraints are re-scaled, moved or rotated this leads to the constraints breaking perhaps the instance you are adding the motor6d to does one of these or something similar when its loading? just food for thought really itll be hard to find the real answer.

It doesn’t have any constraints though.

It works here just fine apparently in this tutorial

Also how do you explain it working for the HumanoidRootPart?

a motor6d is however a constraint also what are you trying to connect the motor6D to in the first place?

I was thinking of the connection between two instances is the constraint, that makes sense now. Are you sure checking if the parent changed is the only solution?
I’m trying to animate a gun equip animation, but that’s irrevelant and didn’t interfere with any of my tests.

i believe you will just have to settle for that solution for now until you can figure out why either the constraint wasnt setting or why it was breaking maybe it something else wasnt there yet like the gun and the wait for character so happened to wait long enough for the gun to spawn or something else there are many reasons it could be.

I found a couple of solutions. :sunglasses:
Here they all are.

  1. You could wait for the Ancestry to change like @SwagMasterAndrew suggested, but if the script (somehow) happens to lag and doesn’t detect the parent change or Roblox makes characters spawn directly inside workspace it won’t work.
Code
game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Character.AncestryChanged:Wait()
		
		local M6D = Instance.new("Motor6D",Character:WaitForChild("UpperTorso"))
		print("M6D Attached! Its parent is "..M6D.Parent:GetFullName())
		wait(10)
		print(M6D.Parent.Name)
	end)
end)
  1. You could do what the Player.CharacterAdded developer api reference did and wait for RunService.Stepped before doing anything to the character.
Code
local RunService = game:GetService("RunService")
game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		RunService.Stepped:Wait()
		local M6D = Instance.new("Motor6D",Character:WaitForChild("UpperTorso"))
		print("M6D Attached! Its parent is "..M6D.Parent:GetFullName())
		wait(10)
		print(M6D.Parent.Name)
	end)
end)
  1. You could just create the Motor6D when you need it, and by then the character would have been created.
2 Likes