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

My NPC Is buggy after too many request of pathfinding .. why ?

Asked by 5 years ago

Hello, I’m doing a routine for NPC , basically they have to move at certain times and do actions . The problem that I encounter is that there is a certain moment when I sequence several travel requests either to this line:

local getPath4 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, fingarcon.Position, 1000)

followPath(getPath4)

local getPath5 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, debutgarcon.Position, 1000)

followPath(getPath5)

local getPath6 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, debutfille.Position, 1000)

followPath(getPath6)

local getPath7 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, finfille.Position, 1000)

followPath(getPath7)

local getPath8 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, debutgarcon.Position, 1000)

followPath(getPath8)

. I don’t know why but at this precise moment the Npc wants to run several paths so it bug and does nothing anymore. I don’t know how to fix this problem so if you know I’d like some help. You can try the script in a NPC with a script that changes time:D .(Sorry For my bad english ..)

Here the entire code for the IA :

local pathService = game:GetService("PathfindingService")



local Chambre = workspace.ChambreJIm

local Cantine = workspace.DemandeRosa

local Chambresortis = workspace.TPcs

local chambreentre = workspace.TPce

local gymnase = workspace.Gymnase

local reserve = workspace.VersRemise

local insidecantine = workspace.InsideCantine

local insidecantine2 = workspace.InsideCantine2

local Chaisecantine = workspace.Earth.KadicVrrai.Cafeteria1.LunchRoomSet1.Jim

local SeatCantine = workspace.Earth.KadicVrrai.Cafeteria1.LunchRoomSet1.Jim.Seat

local Seatchambre = workspace.Earth.KadicInsides.Dorms.Dorms.ChairJim.Seat

local Jimlit = workspace.Earth.KadicInsides.Dorms.Dorms.BedjIM.Seat

local debutgarcon = workspace.DebutdortoirG

local fingarcon = workspace.FinDortoirG

local debutfille = workspace.DebutdortoirF

local finfille = workspace.FindortoirF

local Douche = workspace.Douche1h

local dent = workspace.Brossagededents1h

local dentw = workspace.brossehWatch1

local habille = workspace.HabillageJim

local habillew = workspace.HabillageJimW

local TpEntreGym = workspace.TPgde

local TpSortirGym = workspace.TPgds

local TPAdmi = workspace.TPae

local TPadminBack = workspace.TPas

local SiegeAdmi = workspace.salledesprofs.Jim







-----------------------





function followPath(path)

local points = path:GetWaypoints()

for index, point in pairs(points) do

if point.Action == Enum.PathWaypointAction.Walk then

script.Parent.Humanoid:MoveTo(point.Position)

script.Parent.Humanoid.MoveToFinished:Wait()

end

if point.Action == Enum.PathWaypointAction.Jump then

script.Parent.Humanoid.Jump = true

end

end

end







game.Lighting.Changed:Connect(function()

if game.Lighting.ClockTime >= 5 and game.Lighting.ClockTime <= 5.050 and script.Parent.Step1.Value == false then

script.Parent.Step1.Value = true

script.Parent.Humanoid.Jump = true

local getPath = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, habille.Position, 1000)

followPath(getPath)

script.Parent.Torso.CFrame = CFrame.new(script.Parent.Torso.Position , habillew.Position)

end

if game.Lighting.ClockTime >= 5.500 and game.Lighting.ClockTime <= 5.550 and script.Parent.Step2.Value == false then

script.Parent.Step2.Value = true

local getPath2 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, dent.Position, 1000)

followPath(getPath2)

script.Parent.Torso.CFrame = CFrame.new(script.Parent.Torso.Position , dentw.Position)

wait(10)

local getPath3 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, Douche.Position, 1000)

followPath(getPath3)

end

if game.Lighting.ClockTime >= 6.500 and game.Lighting.ClockTime <= 6.550 and script.Parent.Step3.Value == false then

script.Parent.Step3.Value = true

local getPath4 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, fingarcon.Position, 1000)

followPath(getPath4)

local getPath5 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, debutgarcon.Position, 1000)

followPath(getPath5)

local getPath6 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, debutfille.Position, 1000)

followPath(getPath6)

local getPath7 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, finfille.Position, 1000)

followPath(getPath7)

local getPath8 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, debutgarcon.Position, 1000)

followPath(getPath8)

end

if game.Lighting.ClockTime >= 7.500 and game.Lighting.ClockTime <= 7.550 and script.Parent.Step4.Value == false then

script.Parent.Step4.Value = true

local getPath9 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, Chambresortis.Position, 1000)

followPath(getPath9)

local getPath10 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, Cantine.Position, 1000)

followPath(getPath10)

script.Parent.Torso.CFrame = CFrame.new(script.Parent.Torso.Position , workspace.Rosa.Torso.Position)

game:GetService("Chat"):Chat(game.Workspace.Rosa.Head, "Bonjour ,Jim")

wait(2)

game:GetService("Chat"):Chat(script.Parent.Head, "Salut,Ma grosse")

wait(2)

game:GetService("Chat"):Chat(game.Workspace.Rosa.Head, "LOL... Tien")

local plat = game.ServerStorage.NPCConfig.NPCItem.Plat:Clone()

plat.Parent = script.Parent

Chaisecantine:TranslateBy(Vector3.new(-1.8,0,0))

local getPath11 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, insidecantine.Position, 1000)

followPath(getPath11)

local getPath12 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, insidecantine2.Position, 1000)

followPath(getPath12)

local getPath13 = pathService:ComputeRawPathAsync(script.Parent.Torso.Position, SeatCantine.Position, 1000)

followPath(getPath13)

end







if game.Lighting.ClockTime >= 0 and game.Lighting.ClockTime <= 0.050 and script.Parent.Step2.Value == true and script.Parent.Step1.Value == true and script.Parent.END.Value == true and script.Parent.Step4.Value == true and script.Parent.Step3.Value == true then

script.Parent.Step2.Value = false

script.Parent.Step1.Value = false

script.Parent.Step3.Value = false

script.Parent.Step4.Value = false

script.Parent.END.Value = false

end

end)
0
Im not reading the entire script but maybe its the "many request of pathfinding" and it cant decide which to pathfind to? The_Pr0fessor 595 — 5y
0
but idk why sometime it work .. AfraiEda 8 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Lower response time.

Ad

Answer this question