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

[SOLVED]Pathfinding Ai Refuses to move?

Asked by 2 years ago
Edited 2 years ago

So the ai's main point is to start moving to the player on start i have tried to debug this and it just dosnt want to be fixed i tried it primitivley

as for saying my user name and my rootpart as said below

local Goal = game.workspace:Findfirstchild("amroni2"):Findfirstchild("HumanoidRootPart").Position

Now that worked but this as below does the same thing but dosnt want to


--local path = PathfindingService:CreatePath() --path:ComputeAsync(Root.Position, goal) --local waypoints = path:GetWaypoints() function movetofire(waypoints) local Players = game:GetService("Players") local PathfindingService = game:GetService("PathfindingService") local distance = 5 local Humanoid = script.Parent:WaitForChild("Humanoid") local Root = script.Parent:FindFirstChild("HumanoidRootPart") --local goalval = game.ServerScriptService.Wanted.CURRENTTARGET.Value for i,v in pairs(workspace:GetChildren()) do if v:FindFirstChild("Humanoid") and v ~= script.Parent and game.Players:GetPlayerFromCharacter(v) then local character = v local player = game.Players:GetPlayerFromCharacter(character) --character.Humanoid.Health = 0 print(character) local goal = game.Workspace:WaitForChild(player):FindFirstChild("HumanoidRootPart").Position local path = PathfindingService:CreatePath() local spawnarea = script.Parent:FindFirstChild("SpawnArea").Position local num = 0 local MaxDistance =math.random(50,200) local arrived = false path:ComputeAsync(Root.Position, goal) local storage = game.Lighting local waypoints = path:GetWaypoints() Root:SetNetworkOwner(nil) if goal then for i, waypoint in ipairs(waypoints) do if (goal - Root.Position).Magnitude > MaxDistance then Humanoid:MoveTo(waypoint.Position) else -- Distance from AI is below the maximum distance. Humanoid.WalkSpeed = 0 arrived = true end end end --rander= math.random(1,5) if arrived == true then if script.Parent:FindFirstChild("SpawnArea") and script.Parent:FindFirstChild("SpawnArea2") then print("Spawnable") else script.Parent:Destroy() end local unitnumber = math.random(1,4) local body = script.Parent.Body body.Door1.Transparency = 0 body.Door1.CanCollide = true body.Door2.Transparency = 0 body.Door2.CanCollide = true body.Door1.Decal.Transparency = 0 body.Door2.Decal.Transparency = 0 local spawnarea = script.Parent:FindFirstChild("SpawnArea2").Position local clone = storage:FindFirstChild("Police"):FindFirstChild(unitnumber):Clone() clone.HumanoidRootPart.Position = spawnarea clone.Parent = game.Workspace.WantedAI clone.Archivable = false while true do unitnumber = math.random(1,4) if num < 2 then num = num + 1 if num == 2 then print("BYE") print(num) script.Parent:WaitForChild("SpawnArea"):WaitForChild("Siren"):Stop() wait(100) script.Parent:Destroy() --movetofire:Disconnect() end wait(1) print(num) local spawnarea = script.Parent:FindFirstChild("SpawnArea").Position local clone = storage:FindFirstChild("Police"):FindFirstChild(unitnumber):Clone() clone.HumanoidRootPart.Position = spawnarea clone.Parent = game.Workspace.WantedAI clone.Archivable = false end end print("E") end end end end while wait() do movetofire() end
0
:( amroni2 5 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

I Fixed this

For the people that came:


--local path = PathfindingService:CreatePath() --path:ComputeAsync(Root.Position, goal) --local waypoints = path:GetWaypoints() function movetofire(waypoints) local Players = game:GetService("Players") local PathfindingService = game:GetService("PathfindingService") local distance = 5 local Humanoid = script.Parent:WaitForChild("Humanoid") local Root = script.Parent:FindFirstChild("HumanoidRootPart") --local goalval = game.ServerScriptService.Wanted.CURRENTTARGET.Value local players = game.Players:GetPlayers() local maxDistance = 40 local nearestTarget for index, player in pairs(players) do if player.Character then local target = player.Character local goal = target.HumanoidRootPart.Position local path = PathfindingService:CreatePath() local spawnarea = script.Parent:FindFirstChild("SpawnArea").Position local num = 0 local MaxDistance =math.random(50,200) local arrived = false path:ComputeAsync(Root.Position, goal) local storage = game.Lighting local waypoints = path:GetWaypoints() Root:SetNetworkOwner(nil) if goal then for i, waypoint in ipairs(waypoints) do if (goal - Root.Position).Magnitude > MaxDistance then Humanoid:MoveTo(waypoint.Position) else -- Distance from AI is below the maximum distance. Humanoid.WalkSpeed = 0 arrived = true end end end --rander= math.random(1,5) if arrived == true then if script.Parent:FindFirstChild("SpawnArea") and script.Parent:FindFirstChild("SpawnArea2") then print("Spawnable") else script.Parent:Destroy() end local unitnumber = math.random(1,4) local body = script.Parent.Body body.Door1.Transparency = 0 body.Door1.CanCollide = true body.Door2.Transparency = 0 body.Door2.CanCollide = true body.Door1.Decal.Transparency = 0 body.Door2.Decal.Transparency = 0 local spawnarea = script.Parent:FindFirstChild("SpawnArea2").Position local clone = storage:FindFirstChild("Police"):FindFirstChild(unitnumber):Clone() clone.HumanoidRootPart.Position = spawnarea clone.Parent = game.Workspace.WantedAI clone.Archivable = false while true do unitnumber = math.random(1,4) if num < 2 then num = num + 1 if num == 2 then print("BYE") print(num) script.Parent:WaitForChild("SpawnArea"):WaitForChild("Siren"):Stop() wait(100) script.Parent:Destroy() --movetofire:Disconnect() end wait(1) print(num) local spawnarea = script.Parent:FindFirstChild("SpawnArea").Position local clone = storage:FindFirstChild("Police"):FindFirstChild(unitnumber):Clone() clone.HumanoidRootPart.Position = spawnarea clone.Parent = game.Workspace.WantedAI clone.Archivable = false end end print("E") end end end end while wait() do movetofire() end
Ad

Answer this question