Generated table objects sorted

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Pathfinding GUI

  1. What is the issue? Include screenshots / videos if possible!

I’m trying to make a gui with 2 buttons: Create waypoint and Navigate through them.
The issue is, my knowledge of scripting doesn’t help me write some things.
I make a table, and i don’t know how to put the oldest table object in a variable, and the most recent one.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Yes, i did try searching, but it didnt help.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local waypoints={}

local function AddWaypoint()
local point=Instance.new("Part", game.Workspace)
point.Position=root.Position
point.Anchored=true
point.Shape=Enum.PartType.Ball
point.Transparency=0.7
table.insert(waypoints, point)
--when answered, please put the older and recent table objects in 2 variables: local old, local new
end
2 Likes

Are you trying to find the 2 most recent values in the waypoints table?
I’m not sure what you’re searching for exactly.

table.insert(waypoints, point)

local lengthOfTable = #waypoints
local currentPoint = waypoints[lengthOfTable]
local previousPoint = waypoints[lengthOfTable - 1]
1 Like

I’m trying to find 1 most recent waypoint, and most oldest waypoint(start&end points)
the reason im doing it, is because id place multiple waypoints to go through

2 Likes

This should do that. Again, I may be missunderstanding, but this will give you the point at the start and end of the table.

local startPoint = waypoints[1]
local endPoint = waypoints[#waypoints]
2 Likes

Thanks! I really appreciate your help.

1 Like