Anti Noclip script modification

I’ve been trying to find an anti no clip script for the past few days and I have found one made by “Secretum_Flamma” in 2021. I’ve done some testing and it seemed to work very well. Simplifying anti-no-clip

I am wondering how I could modify it so that if it detects you walking through a wall (no clip) it will smoothly teleport the player to its original position before they started walking through the wall. I am not sure if this would be complicated or not as I am not a scripter.

This is the script in its current form:

local RS = game:GetService("RunService")
local PreviousPositions = {}

local function ANC(Player)
	local function Check(Player, HRP)
		if PreviousPositions[Player.Name] ~= HRP and PreviousPositions[Player.Name] ~= nil then -- check if they moved

			local Distance = (PreviousPositions[Player.Name] - HRP).Magnitude
			local CF = CFrame.lookAt(PreviousPositions[Player.Name], HRP)*CFrame.new(0, 0, -Distance/2)
			local S = Vector3.new(0.01, 0.01, Distance)
			local OP = OverlapParams.new()
			OP.FilterDescendantsInstances = {Player.Character, workspace.Ignore}
			OP.FilterType = Enum.RaycastFilterType.Blacklist
			OP.MaxParts = 1

			local Check = workspace:GetPartBoundsInBox(CF, S, OP)

			local TracePart = Instance.new("Part")
			TracePart.Anchored = true
			TracePart.CanCollide = false
			TracePart.Material = Enum.Material.Neon
			TracePart.Size = Vector3.new(0.25, 0.25, Distance)
			TracePart.CFrame = CFrame.lookAt(PreviousPositions[Player.Name], HRP)*CFrame.new(0, 0, -Distance/2) -- ty @incapaz

			if Check[1] then
				if Check[1].CanCollide == true then
						TracePart.Color = Color3.fromRGB(255, 0, 0)
				else
					TracePart.Color = Color3.fromRGB(0, 255, 0)
				end
			end

			TracePart.Parent = game.Workspace.Ignore

		end
		PreviousPositions[Player.Name] = HRP
	end

	Player.CharacterAdded:Connect(function(Character) -- reset ANC on respawn
		PreviousPositions[Player.Name] = nil
		
		while Character.Humanoid.Health > 0 do
			RS.Heartbeat:Wait()
			Check(Player, Character.HumanoidRootPart.Position)
		end

	end)
end

game.Players.PlayerAdded:Connect(ANC)

for _, Player in pairs(game.Players:GetPlayers()) do -- catch what PlayerAdded missed
	ANC(Player)
end