Hello! so i have a NPC that just chases the player, but when the player spawns, instead of walking down the stairs he just gets to the railing and stops moving due to the invisible barrier, and even when walking down the stairs if the player is next to the he’ll walk into the stairs’ barrier. this also happens when he needs to go around crates. I have tried modifiers but that didn’t work. also, i have created parts to see where is wants to go (waypoints) but none of them are even near the stairs. It seems to be related to the for loop that makes him walk to ever waypoint, because by setting the waypoint index to 2, he seems to be walking around, but the issue is he will then get stuck on benches when climbing them, and he doesn’t get stuck with the for loop. the game is singleplayer so i don’t have to worry about multiple players
script.Parent.Animate.Enabled = false
local anim = script.Parent.Humanoid:LoadAnimation(script.Parent.Stun)
anim:Play()
task.wait(30)
anim:Stop()
script.Parent.Animate.Enabled = true
game.ReplicatedStorage.RemoteEvents.Awaken:FireAllClients()
local pfs = game:GetService("PathfindingService")
local pathparams = {
["AgentHeight"] = 7.5,
["AgentRadius"] = 2.147,
["AgentCanJump"] = true,
["AgentCanClimb"] = true,
["WaypointSpacing"] = math.huge,
Costs = {
["Stairstart"] = 1,
["Stairend"] = 1
}
}
local waypoints = {}
local torso = script.Parent.Torso
local humanoid = script.Parent.Humanoid
local root = script.Parent.HumanoidRootPart
local plrhumanoid = game.Players:GetPlayers()[1].Character.HumanoidRootPart
script.Parent.PrimaryPart:SetNetworkOwner(nil)
game.ReplicatedStorage.RemoteEvents.Death:FireAllClients(root, humanoid, plrhumanoid)
local path
local function Walk()
path = pfs:CreatePath(pathparams)
path:ComputeAsync(torso.Position, plrhumanoid.Position)
local waypoints = path:GetWaypoints()
local success, result = pcall(function()
for _, nextwaypoint in pairs(waypoints) do
local p = Instance.new("Part")
p.Anchored = true
p.Position = nextwaypoint.Position
p.Size = Vector3.new(1, 1, 1)
p.CanCollide = false
p.Parent = workspace.LoadedMaps
humanoid:MoveTo(nextwaypoint.Position)
end
end)
if not success then
warn(result)
end
end
task.spawn(function()
while task.wait() do
Walk()
end
end)
(there is no function in case the path is blocked because it constantly recomputes the path due to it chasing the player)
yeah, otherwise i wouldn’t be able to play
I have debugged a little more and i’ve noticed that if i don’t use a for loop and instead use a specific index number (waypoints[2].Position) it actually goes to the stairs but it gets stopped due to climbing on benches (which it can climb, and the for loops fixes that issue)
local function Walk()
path = pfs:CreatePath(pathparams)
path:ComputeAsync(torso.Position, plrhumanoid.Position)
local waypoints = path:GetWaypoints()
local success, result = pcall(function()
for _, nextwaypoint in pairs(waypoints) do
local p = Instance.new("Part")
p.Anchored = true
p.Position = nextwaypoint.Position
p.Size = Vector3.new(1, 1, 1)
p.CanCollide = false
p.Parent = workspace.LoadedMaps
humanoid:MoveTo(nextwaypoint.Position)
end
end)
if not success then
warn(result)
end
end
I think the for loop is your issue kind of yo issue boy, you can try utilizing break in there when yo need to and also use some if statements IN THE for loop because what can happen is the NPC will just keep going in the path no matter what because it’s stuck in that loop.
so like this for example:
local function Walk()
path = pfs:CreatePath(pathparams)
path:ComputeAsync(torso.Position, plrhumanoid.Position)
local waypoints = path:GetWaypoints()
local success, result = pcall(function()
for _, nextwaypoint in pairs(waypoints) do
if targetfound then
NPC:MoveTo(target)
-- just an example dont take it for real but i think you know how to implement this in yo system
end
local p = Instance.new("Part")
p.Anchored = true
p.Position = nextwaypoint.Position
p.Size = Vector3.new(1, 1, 1)
p.CanCollide = false
p.Parent = workspace.LoadedMaps
humanoid:MoveTo(nextwaypoint.Position)
end
end)
if not success then
warn(result)
end
end
Another possible issue that could be happening is the little task.spawn thing boi, that’s not good for you not good nununu. I tried using task.spawn for waypoints pretty bad son it’s a mistake ESPECIALLY WITH A WHILE LOOP.
task.spawn(function()
while task.wait() do
Walk()
end
end)
the thing is, the game is singleplayer and it always knows where you are, so a target found statement wouldn’t be needed. there is def smth wrong with the for loop since going to the 2nd waypoint seems to make it go around but the issue is if i use that then if it gets on top of benches (which it can with the for loop) it stops moving
by tagging, you just mean the tag feature? i am not really sure how to use it lol, and again, the for loop is a bigger issue since it’s not just the stairs, it is any wall it seems.
this thread is older, i fixed this by adding a MoveToFinished, however that will make it go to the old positions of the player. here’s the newer thread: AI goes to old waypoints