Player Orientation Changes When Part Welded to Player

Hello :smiley:
When I weld a part to a player like this:

Players.PlayerAdded:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait()
	local cl = ServerStorage.Part:Clone()

	local weld = Instance.new("WeldConstraint")
	
	task.wait(5) --only to allow some time to see the change in orientation
	weld.Part0 = char:WaitForChild("HumanoidRootPart")
	print(weld.Part0)
	weld.Part1 = cl; weld.Parent = cl

	cl.Parent = workspace
		
end)

Here is what happens to the player:

As you can see, for the first few seconds the character faces its moving direction. However when the part is welded to the character it keeps the direction it faced the last time before the weld.

Is this normal?

(Sidenote: I played a few games with this rotation-issue, but never noticed something to be welded to the character)

Do you know what is happening or what I am doing wrong?

Thanks :smiley:

2 Likes

I think this is because the Weld is setting the rotation of the RootPart to the Other Part. Maybe you couldnuse a RigidConstraint for this instead?

2 Likes

You could also set the parent of cl to workspace.CurrentCamera which would fix your issue ( altough you can only access that object on the server ).

1 Like

Thanks or the fast response :smiley:
Im not sure if I understood you correctly , but I changed

weld.Part0 = char:WaitForChild("HumanoidRootPart")
	print(weld.Part0)
	weld.Part1 = cl; weld.Parent = cl

to

weld.Part1 = char:WaitForChild("HumanoidRootPart"); weld.Parent = cl
	print(weld.Part0)
	weld.Part0 = cl

to change the RootPart. This didnt solve the issue.
Setting the cl.Parent to workspace.CurrentCamera also didnt help.

With the RigidConstraint I am not sure (partially because I never used it). Maybe I should explain what I am trying to achieve.
I want to have an area around a certain player which does something to any player who comes inside this area. This itself would be simple. I could just check the distance between the player with the area to all other players in a loop. But I also want it to be visible to the other players, thus I need a part on the player.

I should have started with explaining my goal, sorry :smiley:

You could use AlignPosition instead of a Weld.

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character) 
        local cl = ServerStorage.Part:Clone()
        local AlignPosition = Instance.new("AlignPosition",cl)
        local A1 = Instance.new("Attachment", cl)
	    local A2 = Instance.new("Attachment",Character:WaitForChild("HumanoidRootPart"))
	    AlignPosition.RigidityEnabled = true
	    AlignPosition.Attachment0 = A1
	    AlignPosition.Attachment1 = A2
	    cl.Parent = workspace
	end)	
end)

also you should use player.CharacterAdded event to do this since it won’t reappear when you respawn

1 Like

Eventhough this solves the orientation issue, it just makes the part swirl around the player.
I checked the reference on the AlignPosition. If I understand correctly, this involves physics. Maybe thats the problem.
But thank you :smiley:

Here is another one but this time using RigidConstraint.

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character) 
        local cl = ServerStorage.Part:Clone()
        local RigidConstraint = Instance.new("RigidConstraint",Character:WaitForChild("HumanoidRootPart"))
        local A1 = Instance.new("Attachment", Character:WaitForChild("HumanoidRootPart"))
	    local A2 = Instance.new("Attachment",cl)
	    AlignPosition.Attachment0 = A1
	    AlignPosition.Attachment1 = A2
	    cl.Parent = workspace; cl:SetNetworkOwner(nil)
	end)	
end)


1 Like

(First of all, thank you for your efforts :D)

This could work. Currently, on spawn, the player flips to the side but gets up after a few seconds. I played around with the parts shape - doesnt help.
But I will experiment with this tomorrow and see if I can make it work.

I am admittedly a little surprised that this works (to some degree). According to the reference the main difference between a WeldConstraint and a RigidConstraint is that RigidConstraint uses two Attachments instead of one to make it easier to attach accessories to the player.

I will see how it turns out tomorrow.

Thank you very much for trying out so many things :smiley:

Change the RootPriority to -1, change Massless to true. This should solve your problem.

2 Likes

I recommend adding another part to the model and set it to the size of a HumanoidRootPart. Rotate this however you want and try to weld that to the player instead. I am not too sure but I believe this could work.

2 Likes

Big thanks to all of you!

This was finally the solution :smiley:

I am still wondering why this seemingly common and simple problem (having a part fixed to the player) is so poorly documented. But maybe I have been just searching for it the wrong way or have accidentally skipped a certain part of basic knowledge. Mybe it is so obvious and I was just blind ^^.

Either way, thank you again :smiley:

1 Like

I owe you… i was stuck on this for days because i didnt know root priority existed… be blessed

1 Like