Strafing Animation slows down on higher FPS

Hello,

I have made a edit to the roblox animate script that adds backwards strafing, but for some reason when I use a higher FPS than 60, the animation slows down. I know it is something with RunService.Heartbeat, but I have not been able to find a solution for this case.

function onRunning(speed)
	local walktime = 20 
	if speed > 0.01 and speed < 20 then
		playAnimation("walk", 0.2, Humanoid)
		local HumanoidRootPart:BasePart = script.Parent:WaitForChild("HumanoidRootPart")
		-- Bare in mind when you are in a constant speed this doesn't get updated the "Humanoid.Running" Event
		-- you could change this for a Runservice Instead.
		rs.Heartbeat:Connect(function(del)
			-- Compares where the humanoid is heading with movedirection and compares it to look vector of humanoidRootPart
			-- It should usually be -1  but with angles can depend so i've updated to :  -0.65 just
			if (HumanoidRootPart.CFrame.LookVector:Dot(Humanoid.MoveDirection)) <= -0.65 then
				setAnimationSpeed(speed / -14.5)
			else
				setAnimationSpeed(speed / 14.5)
			end
		end)
		pose = "Walking"
	elseif speed > 20 then
		playAnimation("run", 0.25, Humanoid)
		local HumanoidRootPart:BasePart = script.Parent:WaitForChild("HumanoidRootPart")
		-- Bare in mind when you are in a constant speed this doesn't get updated the "Humanoid.Running" Event
		-- you could change this for a Runservice Instead.
		rs.Heartbeat:Connect(function(del)
			-- Compares where the humanoid is heading with movedirection and compares it to look vector of humanoidRootPart
			-- It should usually be -1  but with angles can depend so i've updated to :  -0.65 just
			if (HumanoidRootPart.CFrame.LookVector:Dot(Humanoid.MoveDirection)) <= -0.65 then
				-- Walking backwards
				setAnimationSpeed(speed / -14.5)
			else
				setAnimationSpeed(speed / 14.5)
			end	
		end)
		pose = "Running"
	else
		if emoteNames[currentAnim] == nil then
			playAnimation("idle", 0.2, Humanoid)
			pose = "Standing"
		end
	end
end

Thanks.