I am writing a script to calculate a grounded point to spawn an object on, every time the function calls it prints my defaulting statements, and gets some ridiculous Y value, take a look below and please respond if you can help:

local DoNotIgnore = {"Terrain", "BaseTerrain"};	--[ A table containing the string names of whatever I want the ray to intersect. ]
local Ignore = {game.Players, game.Workspace.CurrentCamera};

function CalcPos(Initial)
	local StartPos = Vector3.new(Initial.X, 2048, Initial.Z)
	local function RayCheck(Start, Dir, Table)
		local NewRay = Ray.new(Start, (Dir - Start).unit * 999)
		local Hit, Pos = game.Workspace:FindPartOnRayWithIgnoreList(NewRay, Table, false, true)
		print(Initial.X ..", ".. Pos.Y ..", ".. Initial.Z ..", ".. (Hit ~= nil and Hit.Name or "No Collision."))
		if Hit ~= nil then
			for N = 1, #DoNotIgnore do
				if Hit.Name ~= DoNotIgnore[N] then
					table.insert(Table, Hit)
					return RayCheck(Pos, Dir, Ignore)
				else
					return Hit, Pos
				end
			end
		end
	end
	local Hit, Pos = RayCheck(StartPos, Vector3.new(StartPos.X, StartPos.Y - 1, StartPos.Z), Ignore)
	if Pos then
		print("Found: ".. Initial.X ..", ".. Pos.Y ..", ".. Initial.Z)
		return Vector3.new(Initial.X, Pos.Y, Initial.Z)
	else
		print("Pos not found, defaulting...")
		return Vector3.new(Initial.X, 0, Initial.Z)
	end
end

delay(10, CalcPos(Vector3.new(0, 0, 0)))

Again, please respond if you can, any insight to solving this problem will be greatly appreciated.

4 comments

0

And to anyone who's wondering, yes, I like to make my comments/notations fancy... XD

0

For your 'fancy' comments, it should be 2 Square Parenthesis and not 1. Like so: --[[Like this]]

0

You twit, i'm not going for extended comments, its just my style.

0

Sorry, someone else said the exact same thing to me and I gave them the same reply.