AIs colliding in central script

Im making a fnaf inspired game and i made four AIs so far but as im integrating and testing the second AI the first one blocks the second one.

what i mean is that unless the first AI is finished doing its thing only then will the second AI start. I want them to move asynchronously. thanks!

--// Services //--
local RS = game:GetService("ReplicatedStorage")

--// Variables //--
--Postitions--
local VentGuyPoints = RS:WaitForChild("VentGuyPoints")
local LeftGuyPoints = RS:WaitForChild("LeftGuyPoints")
local RightGuyPoints = RS:WaitForChild("RightGuyPoints")
--------------

--Folders--
local Hallucinations = RS:WaitForChild("Hallucinations")
-----------

--Stopers--
local Locker = workspace.Locker
local RightDoor = workspace.RightDoor
local LeftDoor = workspace.LeftDoor
-----------


--// Module scripts //--
local VentGuyBehavior = require(script.VentGuyAI)
local LeftGuyBehavior = require(script.LeftGuyAI)
local RightGuyBehavior = require(script.RightGuyAI)
local OfficeGuyBehavior = require(script.OfficeGuyAI)

--// Main Code //--

--Vent Guy--
local function initializeVentGuy(ventGuy)
	print("vent guy executed")
	local VentGuyAI = VentGuyBehavior.new(ventGuy, VentGuyPoints, Locker)
	VentGuyAI:Run()
end

-- Initialize VentGuy
initializeVentGuy(Hallucinations.VentGuy:Clone())
------------

--Right Guy--
local function initializeRightGuy(rightGuy)
	print("Right guy executed")
	local RightGuyAI = RightGuyBehavior.new(rightGuy, RightGuyPoints, RightDoor)
	RightGuyAI:Run()
end

-- Initialize RightGuy
initializeRightGuy(Hallucinations.RightGuy:Clone())
-------------

--Left Guy--
local function initializeLeftGuy(leftGuy)

end

-- Initialize LeftGuy

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

--Office Guy--
local function initializeOfficeGuy(officeGuy)

end

-- Initialize OfficeGuy

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

i’m assuming :Run() has a loop for where the AI moves and that could be where it blocks the other AI from continuing.

you might need to use task.spawn() to keep the script going

   local function initializeRightGuy(rightGuy)
	     print("Right guy executed")
         task.spawn(function()
	         local RightGuyAI = RightGuyBehavior.new(rightGuy, RightGuyPoints, RightDoor)
	         RightGuyAI:Run()
        end)
    end

yeah it did have a loop in their modules. Thanks so much i completely forgot about task.spawn() since i dont use it too often. Thanks a lot it definitely works!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.