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

How do I make this script follow the player?

Asked by 3 years ago

I'm a beginner scripter I created this script for my ai that finds closest player but it doesn't follow the players

local PathfindingService = game:GetService("PathfindingService")
local robot = script.Parent
local humanoid = robot.Humanoid
local maks = 500
function gtp()
    local cp = robot.HumanoidRootPart.Position
    local p = game.Players:GetChildren()
    for i,v in pairs(p) do
        local pos = p.Character.HumanoidRootPart.Position
        local mpos = math.min(cp-pos)
        if mpos <= maks then

            local path = PathfindingService:CreatePath()
            path:ComputeAsync(cp,pos)
            local waypoints = path:GetWaypoints()
            for _,waypoint in pairs(waypoints) do
                humanoid:MoveTo(waypoint)
                humanoid.MoveToFinished:Wait()
            end
            break
        end

    end

end
0
what is following you memekarmhimal 10 — 3y

Answer this question