All my Npc’s go to the same wall when I spawn them in, they are supposed to move randomly.
Pathfinding Script:
local PATHFINDING_SERVICE = game:GetService("PathfindingService")
local RANDOM_POSITIONS = {}
local HUMAN = script.Parent
local ROOT = HUMAN.Parent.HumanoidRootPart
local RNG = Random.new()
local walkRange = 10
local posToGen = 5
local canJump = true
for i = 1,posToGen do
local rX = RNG:NextInteger(-walkRange,walkRange)
local rZ = RNG:NextInteger(-walkRange,walkRange)
table.insert(RANDOM_POSITIONS,Vector3.new(rX,ROOT.Position.Y,rZ))
end
if canJump then
spawn(function()
while canJump do
local waitToJump = RNG:NextInteger(1,3)
local jumpChance = RNG:NextInteger(1,2)
if jumpChance == 1 then
HUMAN.Jump = true
end
wait(waitToJump)
end
end)
end
spawn(function()
while true do
local randomPos = RANDOM_POSITIONS[RNG:NextInteger(1,#RANDOM_POSITIONS)]
local moveToCooldown = RNG:NextNumber(.5,1)
local createdPath = PATHFINDING_SERVICE:CreatePath()
local computedPath = createdPath:ComputeAsync(ROOT.Position,randomPos)
for _,waypoint in pairs(createdPath:GetWaypoints()) do
if waypoint.Action == Enum.PathWaypointAction.Walk then
HUMAN:MoveTo(waypoint.Position)
elseif waypoint.Action == Enum.PathWaypointAction.Jump then
HUMAN.Jump = true
end
HUMAN.MoveToFinished:Wait()
end
wait(moveToCooldown)
end
end)
If anyone knows how to make them move randomly, instead of into a wall, that would be very helpful. Thankyou! (The dummies are in R6 also.)