I've been working on pathfinding ai, and I know how to get an ai to walk around randomly and from one point to another, but I just haven't been able to figure out how to get a player's position so the ai follows them. I haven't been able to get the value out of event functions that get the players position. How would I return the value so I could use it as the end goal of the move function? Here's my code. Any help is appreciated :)
function move()
local human = script.Parent.Humanoid
local torso = script.Parent.HumanoidRootPart
local service = game:GetService("PathfindingService")
script.Parent.HumanoidRootPart.Anchored = false
local path = service:CreatePath()
path:ComputeAsync(torso.Position,game.ReplicatedStorage.Vector3Value.Value) -- DONT KNOW HOW TO GET PLAYER POSITION
local waypoints = path:GetWaypoints()
-- getting player position
game.Players.PlayerAdded:Connect(function(player)
game.Players.CharacterAdded:Connect(function(character)
local value = character.HumanoidRootPart.Position
game.ReplicatedStorage.Vector3Value.Value = Vector3.new(character.HumanoidRootPart.Position) -- DONT KNOW HOW TO GET PLAYERS POSITION OUT OF THIS FUNCTION
end)
end)
for i, v in pairs(waypoints) do
human:MoveTo(v.Position)
human.MoveToFinished:Wait(2)
end
end
while wait(3) do
move()
end
