Like the humanoid root part? The npc or player?
its the waypoint position???
What line? Sorry I thought the object is nil.
its probably caused by the script not being able to find last waypoint or something
if waypoints[#waypoints].Position ~= plrhrp then
It doesnt exeist the waypoint
Eeeeered
how would it not exist it finds the last waypoint tho
gtg to sleep my dad tell me to sleep
Try this out:
local pfs = game:GetService("PathfindingService")
local path = pfs:CreatePath()
local success, errors = pcall(function()
path:ComputeAsync(v.HumanoidRootPart.Position, plrhrp)
end)
if success then
if path.Status ~= Enum.PathStatus.Success then
return
end
local waypoints = path:GetWaypoints()
if waypoints[#waypoints].Position ~= plrhrp then
--do stuff
end
else
warn("ERROR: " .. tostring(errors))
end
A table inside a table could that be the problem?
Honestly I don’t think I can help the best I can do is
for _,waypoint in ipairs(#waypoints) do
if waypoint.Position ~= plrhrp then
—Do stuff
end
end
What do you mean by that?
(ignore char)
Isn’t waypoints a table?
waypoints[#waypoints]
If you’re trying to detect whether the target is moving away from the calculated end-point of the Pathfinding, I suggest doing something like this instead:
if (waypoints[#waypoints].Position - plrhrp).Magnitude > 5 then
-- do stuff
end
-- OR THIS IF YOU HAVE THE PLAYER OBJECT (THIS IS LESS INTENSIVE THAT MAGNITUDE)
if plr:DistanceFromCharacter(waypoints[#waypoints].Position) > 5 then
-- do stuff
end
In my experience with AIs, I’ve personally found issues with checking whether the player is SPECIFICALLY at the end-point because a single flinch or movement of a player would make the AI have to recalculate again which is pretty memory-expensive.
#
is a length operator. And array[#array]
is the most simplest way of getting the last/end value of a array. In most languages, arrays start with 0 instead of 1 (which is what Lua does).
And no, you are not putting a table inside a table because you are adding #
which returns the length of a table, not itself.
Here’s an example:
local tbl = {41,"owo",412,14,25,24,254,23}
print(#tbl)--8
print(tbl[#tbl]) --23
print(tbl[8])--23
im tryna detect if the last waypoint’s position is equal to the plrhrp
there are no errors but the position not changing
What exactly are we looking at here?
its uh me printing waypoint[#waypoint].Positiob