[Please Help!] How to add IK constraints with script?

I am working on adding moving pedals to my driving game. I have an IK that gets added to the player’s Humanoid when they enter the car, and it works fine other than the knee bends backwards. I have tried using a script to add a HingeConstraint to the character on spawn, but it doesn’t affect the IK at all, it just says that it’s out of the limits.
Here’s a screenshot of the problem:


The leg in the back is the one with the problem, and the one in front is what I kind of want it to look like.
Here’s a script in StarterCharacterScripts that adds the constraint:

local character = script.Parent
local player = game.Players:GetPlayerFromCharacter(character)
player:WaitForChild("IsInStartGUI").Value = true
game.ReplicatedStorage.Events.MainMenu:FireClient(player, true)

game.ReplicatedStorage.Events.CarAdded.Event:Connect(function(car)
	if character.Humanoid.RigType == Enum.HumanoidRigType.R15 then
		local one = character.RightUpperLeg.RightKneeRigAttachment
		local two = character.RightLowerLeg.RightKneeRigAttachment
		local attach0 = nil
		local attach1 = nil
		if one:FindFirstChild("Attachment") then
			attach0 = one:FindFirstChild("Attachment")
			attach1 = two:FindFirstChild("Attachment")
		else
			attach0 = Instance.new("Attachment")
			attach0.Parent = one
			attach1 = Instance.new("Attachment")
			attach1.Parent = two
			one.WorldCFrame = two.WorldCFrame
		end
		local rightKneeConstraint = Instance.new("HingeConstraint")
		rightKneeConstraint.Parent = character.Humanoid
		rightKneeConstraint.Name = "RightKneeConstraint"
		rightKneeConstraint.LimitsEnabled = true
		rightKneeConstraint.UpperAngle = 10
		rightKneeConstraint.LowerAngle = -90
		rightKneeConstraint.Attachment0 = attach0
		rightKneeConstraint.Attachment1 = attach1
	end
end)

The CarAdded event runs once the player sits in the seat (which is right after they select their car).

2 Likes

Does anyone have any ideas? I really need help with this

2 Likes

Google searches don’t come up with anything useful.

1 Like

Still in beta, have you tried this?

1 Like

It works! Thank you so much! I’m surprised I didn’t see that earlier.

1 Like

No worries you are not the only one. Hopefully it will get updated soon.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.