Issue with constraint - Part moving around

why he turns around?

I want to stand up straight

https://gyazo.com/4ba7f083537cf2cecca055643d3d4cd8

Tool.ClickDetector.MouseClick:Connect(function(Player)
if Debounce == false then
    Debounce = true
    local HingeConstraint= Instance.new("HingeConstraint", Player.Character.RightHand)
	local AttachmentA = Instance.new("Attachment", Tool)
	local AttachmentB = Instance.new("Attachment", Player.Character.RightHand)
	Tool.Parent = Player.Character
	HingeConstraint.Attachment0 = AttachmentA
	HingeConstraint.Attachment1 = AttachmentB
	TakenC:FireClient(Player)
end
end)

Because that’s what hinge constraints do and it’s basically the same as trying to hold a spinning gyroscope. They are meant for things that rotate and aren’t static. You should either use WeldConstraints or ManualWelds/Motor6Ds.

Tool.ClickDetector.MouseClick:Connect(function(Player)
	if Debounce == false then
		Debounce = true
		local WeldConstraint= Instance.new("WeldConstraint", Player.Character.RightHand)
		Tool.Parent = Player.Character
		Tool.CFrame = Player.Character.RightHand.CFrame
		WeldConstraint.Part0 = Tool
		WeldConstraint.Part1 = Player.Character.RightHand
	
		TakenC:FireClient(Player)
	end
end)

If you make a part inside the Tool named Handle then you won’t need to apply any constraints, if needed you can use CloneTroopers1019’s Tool Editor Plugin to ensure the correct way to hold.

It doesn’t seem like a “Tool” instance though as you can’t place an attachment into something that isn’t a BasePart.

1 Like

Ah fair point, I didn’t notice that.
You can always make this a Tool Instance if it doesn’t create any problems.

Also, don’t use the second argument of Instance.new as it has a huge optimisation difference.
You can read more here:

2 Likes

Worth adding: its not just about optimisation. In some cases, this can lead to unintended effects, because the instance gets added to various pipelines and background processes start operating once the instance gets attached to the DataModel.

1 Like

More importantly, you should parent them after every other property was set.
These 2 examples are the same regarding performance:
local inst = Instance.new("Part",workspace)
local inst = Instance.new("Part"); inst.Parent = workspace

The 2nd argument just removes the need to set the parent after the object’s creation, which can be a bit useful if you don’t plan on changing it’s properties within the current frame.

2 Likes