Issues trying to recreate My Restraunt NPC's

Hello everyone! I am trying to recreate the NPC movement from the popular game My Restraunt and I have taken an OOP approach in order to make new customers, but I still can’t figure out how to spawn 4 customers at a time. At the moment, I only spawn 1 per 0.5 seconds and it looks kind of ugly. In the game, 4 customers spawn at the same time, and go to their designated table all in sync. Any help would be appreciated! If you have further questions about what I am trying to achieve please ask!

You can make a function that is called every 0.5 or 1 second using wait() to prevent spawning them all at the same time. to spawn 4 at the same time, call a function when necessary, which spawns 4 npcs at the same time;

-- Spawn an NPC function:
local function SpawnRandomNPC()
--Spawn npc code...
end)

--Spawn 4 NPCs at the same time:
local function QuadNPCSpawn()
SpawnRandomNPC()
wait() --not necessary
SpawnRandomNPC()
wait() --not necessary
SpawnRandomNPC()
wait() --not necessary
SpawnRandomNPC()
end)

P.S. I’m not THAT experienced with code, but try this and let me know if it works!

1 Like

to add to your code, I would make use of for loops to make it more efficient

-- Spawn an NPC function:
local function SpawnRandomNPC()
	--Spawn npc code...
end

local function SpawnNPCs(npcCount) -- You will call this function whenever an NPC needs to spawn
-- npcCount is the amount of NPCs you wish to spawn
	for i=1, npcCount do
		SpawnRandomNPC()
	end
end

This is only an example though

2 Likes

the issue is that its in a for loop and its not a function but rather a constructor so Im confused how I can achieve this?

What’s the problem with a loop?