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.
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)
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.
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.
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.
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)