So I have 2 functions, the 1st function has no wait in it, and the 2nd function has a wait in it. The reason I don’t want to call the 2nd function after the 1st function ran is because the wait will also be transferred to the first function
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried while true do, but it no work since I can’t call the 2nd function
local function npcMaker()
local npcChooser = npcs[math.random(1, #npcs)]
local npc = npcChooser:Clone()
npc.HumanoidRootPart.CFrame = spawner.CFrame
npc.Parent = workspace.NPCs
local humanoid = npc.Humanoid
--Where NPC move to before reaching the line
humanoid:MoveTo(workspace.ConnerPath.Position)
humanoid.MoveToFinished:Wait() -- The reason why the wait is needed
humanoid:MoveTo(workspace.DoorPath.Position)
humanoid.MoveToFinished:Wait()
if #PizzaLineNpcs == 0 then
humanoid:MoveTo(PizzaLine.Position)
else
humanoid:MoveTo(PizzaLineNpcs[#PizzaLineNpcs].HumanoidRootPart.Position + DistanceBetweenNPC)
end
table.insert(PizzaLineNpcs, npc)
end
local function npcToRegister(path)
-- Make NPC move to a Cashier
npcMaker() -- I don't want to call this here, because it will wait and there are multiple registers
end
Sounds like you’re wanting to call a function without it yielding for the function to complete. To do this you want to run this on a separate thread. You can do this with spawn or coroutines.
However, do consider the following, as issues can apply to both spawn (which can yield) and coroutines:
fastSpawn is essentially just the following, using your example to execute that function on a separate thread:
local bindable = Instance.new("BindableEvent")
bindable.Event:Connect(function()
npcMaker()
end)
bindable:Fire()
bindable:Destroy()