I made this module, have any feedback?

Module:

local PathfindingModule = {}

function PathfindingModule.CreatePath (Script: Script, Character: Model, EndPosition: Vector3, CostsTable: {any}, CanClimb: boolean, CanJump: boolean, Radius: number, MoveToPosition: boolean, ShowPath: boolean, PathVisibleTime: number, DestroyValue: boolean, IsGui: boolean)
	if not Character:IsA("Model") then warn("Selected Instance is not a Model.") return end
	if Character == nil or not Character:FindFirstChildWhichIsA("Humanoid") or EndPosition == nil or Character.PrimaryPart == nil then warn("Invalid Character Properties") return end
	
	if DestroyValue == nil then DestroyValue = true end
	if CanClimb == nil then CanClimb = false end
	if CanJump == nil then CanJump = false end
	if ShowPath == nil then ShowPath = false end
	if Script == nil and ShowPath == true then warn("No script provided to store value.") return end
	if MoveToPosition == nil then MoveToPosition = true end
	if IsGui == nil then IsGui = false end
	
	if Radius == nil then Radius = 2 end
	if CostsTable == nil then CostsTable = {} end
	
	if ShowPath == true then
		
		local PathParent = Instance.new("Model")
		PathParent.Parent = workspace
		PathParent.Name = 'Path'
		
		local Value = Instance.new("ObjectValue", Script)
		Value.Name = 'Model'
		Value.Value = PathParent
	end
	
	local PathfindingService = game:GetService("PathfindingService")
	local HumanoidRootPart = Character.PrimaryPart
	local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
	
	local Path = PathfindingService:CreatePath({
		AgentRadius = Radius,
		AgentCanJump = CanJump,
		AgentCanClimb = CanClimb,
		
		Costs = CostsTable
	})
	
	local success, errorMessage = pcall(function()
		Path:ComputeAsync(HumanoidRootPart.Position, EndPosition)
	end)
	
	if success and Path.Status == Enum.PathStatus.Success and MoveToPosition then
		
		local NumberRepeated = 0
		
		for _, Waypoint in pairs(Path:GetWaypoints()) do
			
			NumberRepeated += 1
			
			if ShowPath == true then
				
				local Part = Instance.new("Part")
				Part.Anchored = true
				Part.CanCollide = false
				if not IsGui then
					Part.Transparency = 0
					Part.Shape = Enum.PartType.Ball
					Part.Material = Enum.Material.Neon
				else
					Part.Transparency = 1
					
					local Gui = Instance.new("BillboardGui", Part)
					Gui.Size = UDim2.fromScale(1, 1)
					
					local Frame = Instance.new("Frame", Gui)
					Frame.Size = UDim2.fromScale(1, 1)
					Frame.Transparency = 0
					Frame.BackgroundColor3 = Color3.new(1, 1, 1)

					local Corner = Instance.new("UICorner", Frame)
					Corner.CornerRadius = UDim.new(100, 0)
				end
				
				Part.Size = Vector3.new(1, 1, 1)
				Part.CastShadow = false
				Part.Position = Waypoint.Position + Vector3.new(0, 1, 0)
				Part.Name = 'Waypoint' .. tostring(NumberRepeated)
				Part.Parent = Script:FindFirstChild("Model").Value
				Part:SetAttribute("WaypointNumber", NumberRepeated)
				
				if NumberRepeated == #Path:GetWaypoints() then
					NumberRepeated = 0
					if DestroyValue == true and ShowPath == true then
						local Value = Script:FindFirstChild("Model")
						if PathVisibleTime ~= -1 and PathVisibleTime ~= nil then
							repeat task.wait() until #Value.Value:GetChildren() <= 1
							Value.Value:Destroy()
						end
						Value:Destroy()
					end
				end
				
				if PathVisibleTime ~= nil and PathVisibleTime ~= -1 then
					task.delay(PathVisibleTime, function()
						Part:Destroy()
					end)
				end
			end
			
			Humanoid:MoveTo(Waypoint.Position)
			
			if Waypoint.Action == Enum.PathWaypointAction.Jump and CanJump == true then
				Humanoid.Jump = true
			end
			
			Humanoid.MoveToFinished:Wait()
		end
	elseif errorMessage ~= nil and MoveToPosition then
		warn('Failed because ' .. errorMessage)
	elseif success and Path.Status ~= Enum.PathStatus.Success and errorMessage == nil and MoveToPosition then
		warn('Pathfinding Failed for Unknown Reason.')
	elseif success and Path.Status == Enum.PathStatus.Success and not MoveToPosition then
		return Path
	end
end

return PathfindingModule

This was me testing my scripting knowledge and it worked!

Any feedback is appreciated!!! :happy3:

if only getfenv wasn’t deprecated…

local defaults = {
	DestroyValue = true,
	CanJump = false,
	ShowPath = false,
	MoveToPosition = true,
	IsGui = false,
	Radius = 2,
	CostsTable = {}
}
for i,v in defaults do
	if not getfenv()[i] then
		getfenv()[i] = v
	end
end

That a bad design you provided
Never inlinable and abstracts awey logic for no gain

1 Like

Even if it wasn’t, any mention of it (even if it’s not called, like x = getfenv) in a script will force that script into --!optimize 0. Horrible idea to use it

1 Like

I meant to say “If only getfenv() didn’t screw absolutely everything up”. Of course, getfenv bad, but it feels much cleaner.

Don’t use it. I thought I’d share it, but I never told anyone to use it.