Motor6D on a new player script not working for no reason

this problem has been extremely frustrating and hopefully someone here will know what to do.
I am trying to implement code that simply places a motor6D in a player’s torso when they join, so that it can be used to run animations.
here’s the code:

game.Players.PlayerAdded:Connect(function(player)
		player.CharacterAdded:Connect(function(char)
			local M6D = Instance.new("Motor6D")
			M6D.Name = "ToolGrip"
			M6D.Parent = char.UpperTorso
	end)
end)

it’s basically a carbon copy of the code AlvinBlox uses in his videos. It’s identical to 5 other solutions i found on the forums, and more than that it doesn’t have any reason not to work. it just waits until a player is added and staples a motor6d to them. it’s foolproof. it should work and it doesnt. the function runs and it just does nothing. i put it into 3 different server scripts, and even into one that had functioning code. it just sits there like a brick.
im going to stop typing before i make an even bigger fool of myself. i would be very grateful for any help or insight anyone could give. i can’t even think straight this thing has me so mad.
thank you for reading my suffering.

edit: i was so steamed earlier that i accidentally made a garbage post. heres whats going on:
the script itself is just trying to make a motor6d and parent it to the joining player’s Upper Torso. the intention is to set the motor’s part 0 to the torso and part 1 to a tool when the player pulls it out so that the tool can animate.
the function itself runs. i have pasted all kinds of prints into every part of it, and before and after it. the whole thing runs and it doesn’t throw any errors: it simply does not do what it is supposed to do. it seemingly does nothing.
like i said, i just dont know.

1 Like

You don’t really explain what is not working and what you expect to happen. I assume you want to observe a motor6d being created and parented to the player’s upper torso, and that, in the scripts current state, this doesn’t happen. First, I would either use prints or breakpoints to check if the functions connected to the player added and character added events are being called. One possible reason nothing may be happening is because the player may already be in the game so the player added event is not firing for them.

2 Likes

thanks for replying. im sorry my post was so awful, i was absolutely fuming when i wrote it and wasnt really thinking straight.
anyways, you have it right: the whole point it to make the motor and parent it to the player’s torso. i have used prints to check if the whole thing runs, and it does. it even continues to run code after this bit if there is any placed after it. this code doesn’t throw any errors either, which is the most confusing part. it runs through the code, and then just does nothing.
The prints inside of both checks ran, but its possible you are right. i will check again to see if the player being in the game already is interfering with the event. thank you so much for your comment.

Is this solved by any chance? I’m here still having the same issue (I know this is an old topic).

1 Like

i did, actually. it turned out that player.CharacterAdded would fire before the player character had actually finished being put into the workspace, and since the code ran so fast it would still finish before the character was actually in the game, counterintuitively.

anyway, the solution was just to make it wait for the PC with a WaitForChild.
here’s the code:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(player)
		local playerChar = workspace:WaitForChild(player.Name)
		local M6D = Instance.new("Motor6D")
		M6D.Name = "ToolGrip"
		M6D.Parent = playerChar.UpperTorso
	end)
end)

hopefully this didn’t come to late to be useful. good luck with your project!

2 Likes