Move Point away from the closest edge

I have a bit of setup before I completely delve into the problem: I’m making a script that will automatically return you to where you were last on the ground if you fell off the map.

you can’t normally jump in this game so whenever you fall off, you usually just appear at the very edge of the part you fell off of. I need the part to be further from the edge of the part so that you don’t accidently fall off again

So far i haven’t found any solutions to this problem.
TECHNIQUELY I could just make a raycast in all 4 cardinal directions, but i fell like that’s the wrong way to do this

heres the code i have right now (I removed alot but its still basically the what it show in the video)

local Character = script.Parent
local HumanoidRootPart:Part = Character:WaitForChild("HumanoidRootPart")
local RunService = game:GetService("RunService")
local LastGroundPosition = Vector3.new()
function BeReady()
	local Perams = RaycastParams.new()
	Perams.FilterDescendantsInstances = {Character, workspace.Hitboxes}
	Perams.FilterType = Enum.RaycastFilterType.Exclude
	local Raycast = workspace:Raycast(HumanoidRootPart.Position, Vector3.new(0,-6,0), Perams)

	if Raycast then
		LastGroundPosition = Raycast.Position
	end
end

function Save()
	--DamageFunction.Scripts.Normal(Humanoid, 2, "Enviorment", nil) Irrelevant script, + ill update it later

	Character:PivotTo(CFrame.new(LastGroundPosition+Vector3.new(0,3,0)))
end

RunService.Heartbeat:Connect(function()
	BeReady()

	if HumanoidRootPart.Position.Y <= -10 then
		--KnockbackScript:Stop() Another irrelevant script
		Save()
	end
end)

in theory what i think you should do, if you already have the “rollback” system, every frame or 2 do checks for if the ground under the character isnt air. if its air then continue, otherwise continue rolling back until theres ground.

If your game doesn’t have complex terrain, you could simply mark all return-able surfaces with an invisible part/the parts themselves. Though extra part count is the drawback.

You could also track in intervals where the player was, and when they spawn back, go through those positions and find the last one where they are on valid ground. I think this is the best solution out of these. This is similar to @ertiziodon1’s idea.

And an obsurd idea is to raycast down above the player’s last position in a grid to find a large enough surface to spawn on… but obviously there are major drawbacks to this.