The abrupt end of IK (in-game)

Hi everyone, today I wanted to make a door with IK animation of the player. Everything works, but I want when we leave the Part the hand smoothly returns to the original position, not as in the video, the animation is abruptly interrupted and the hand returns to the original position.


At the end of the video you can see that when I leave Part the IK animation is abruptly cut off, and I want the arm to smoothly return to its original position.

local part = script.Parent

-- Function to be called when a player touches the part
local function onTouch(hit)
	local character = hit.Parent
	local humanoid = character:FindFirstChildOfClass("Humanoid")

	-- Check if the humanoid exists and IK is not in progress
	if humanoid and humanoid:FindFirstChild("IKControl") and humanoid:FindFirstChild("IKControl").Enabled == true then
		return
	end

	-- Check if the humanoid exists
	if humanoid and not humanoid:GetAttribute("IKInProgrss") then
		humanoid:SetAttribute("IKInProgrss", true)

		-- Create IKControl if it doesn't exist
		local ikControl = humanoid:FindFirstChild("IKControl")
		if not ikControl then
			ikControl = Instance.new("IKControl")
			ikControl.Parent = humanoid
			ikControl.Type = Enum.IKControlType.Position
			ikControl.EndEffector = character:FindFirstChild("LeftHand", true)
			ikControl.ChainRoot = character:FindFirstChild("LeftUpperArm", true)
		end

		-- Set the IKControl target
		ikControl.Enabled = true
		ikControl.Target = workspace.Door.Base.Attachment

		-- Wait for 1 second
		wait(1)

		-- Clear the IKControl target
		ikControl.Enabled = false
		ikControl.Target = nil

		-- Reset the IKInProgrss attribute
		humanoid:SetAttribute("IKInProgrss", false)
	end
end

-- Connect the onTouch function to the Touched event of the part
part.Touched:Connect(onTouch)

I never heard of this IK before but why don’t u try checking if the player is still touching the part with get touching parts or something? Before playing or stoping the animation?

1 Like