IK smoothly script

Hello, I have a problem with the script below, as I am trying to make a script like IK smooth player character moving along terrain for realistic game. The problem is in the code below. Thank you for your answers.

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local terrain = workspace:WaitForChild("Terrain")
local speed = 10

humanoid.WalkSpeed = speed

local function onCharacterAdded(character)
    character.Humanoid.Died:Connect(function()
        character.Humanoid.WalkSpeed = speed
    end)
end

player.CharacterAdded:Connect(onCharacterAdded)

terrain.Touched:Connect(function(part)
    if part.Parent == character then
        local point = terrain:WorldToTerrainCoordinates(part.Position)
        local normal = Vector3.new(0, 0, terrain:GetHeight(point))
        character:MoveTo(part.Position + normal)
    end
end)