Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Currently making a Pathfinding AI that follows player, but I'm having difficulties. Can aynone help?

Asked by 5 years ago
Edited 5 years ago

Hi all, so I'm currently making an AI follow a player around, as if the AI is a zombie. I'm having one problem with it, and the output is quiet about what's wrong with the script.

For some reason the AI does not follow the player, and the output does not say anything about it. I'm curious on what I've done wrong on my scripts, as it looks fine to me, but I'm not sure if it looks fine to you.

Here's the script in case you need to see if there's anything wrong with it, and the script is not inside the NPC:

-- Pathfinding Service

local PathfindingService = game:GetService("PathfindingService")

-- Variables
local goofyplsm9 = game.Workspace.goofyplsm9
local humanoid = goofyplsm9.Humanoid
local humanoidRootPart = goofyplsm9.HumanoidRootPart
local player = game.Players.LocalPlayer
local character = player.Character

-- What goofyplsm9 will follow.
local Survivor

-- Variables for Survivor.
local Survivor = player.character

-- Variable to keep track of goofyplsm9's destination.
local currentDestination = character

if Survivor == true then

        -- Variables for goofyplsm9's start and goal path.
        local startingposition = humanoidRootPart.position
        local goalposition = Survivor

        -- Goofy needs to find a path to the player. Let's fix that.
        local path = PathfindingService:FindPathAsync(startingposition, goalposition)
        local waypoints = path:GetWaypoints()

        -- If goofyplsm9 reaches the Survivor, it will loop it's seqeunce.
    for waypointIndex, waypoint in pairs(waypoints) do
        local waypointPosition = waypoint.Position
        -- Make the stupid noob move to the survivor
        humanoid:MoveTo(waypointPosition)
    end
end

goofyplsm9 is the NPC that I'm trying to get to follow me or a player.

I was following an article on the RobloxDev Wiki website and it showed me how to script an AI to move from one point to another point, then repeats itself over and over again. If I made any mistakes making this script from looking at the article, please let me know.

Thanks.

0
I assume it's an issue with changing what it follows. I've tried the same thing for nearest player, and it didn't move. chexburger 358 — 5y
0
check lines 9 and 10 bud User#19524 175 — 5y
0
Oof mixgingengerina10 223 — 5y

Answer this question