I’ve been trying to create a customer system for the last few days and I thought I was getting it but after testing it with multiple players, it’s doesn’t work like I thought it was going too. Does anyone know what’s going wrong?
local CustomerManager = {}
CustomerManager.__index = CustomerManager
ServerStorage = game:GetService("ServerStorage")
local pfs = game:GetService("PathfindingService")
local path = pfs:CreatePath({
Costs = {
RestrictedZone = math.huge
}
})
function CustomerManager.StartSession(player)
local Tycoons = game.Workspace.Tycoons
if Tycoons:FindFirstChild(player.Name.."_Tycoon") then
local Tycoon = Tycoons:FindFirstChild(player.Name.."_Tycoon")
local CashoutQueue = {}
createCustomers(Tycoon, CashoutQueue, 3)
end
end
function followPath(npc, goal)
path:ComputeAsync(npc.HumanoidRootPart.Position, goal.Position)
wps = {}
if path.Status == Enum.PathStatus.Success then
wps = path:GetWaypoints()
wpIdx = 1
npc.Humanoid:MoveTo(wps[wpIdx].Position)
end
end
function moveQueue(Tycoon, CashoutQueue)
for i = 1, 3 do
local npcID = CashoutQueue[i]
if npcID then
followPath(npcID, Tycoon.Customer_Waypoints.Queue[i])
end
end
end
function createCustomers(Tycoon, CashoutQueue, amount)
for i = 1, amount do
local npcClone = ServerStorage.NPC:Clone()
npcClone:SetPrimaryPartCFrame(Tycoon.CustomerSpawn.CFrame)
npcClone.Name = "NPC_"..i
npcClone.Parent = Tycoon.Customers
pathToBrowse(Tycoon, CashoutQueue, npcClone)
wait(math.random(5,10))
end
end
function pathToBrowse(Tycoon, CashoutQueue, npcClone)
local npc_waypoints = {}
for i, v in pairs(Tycoon.Customer_Waypoints:GetChildren()) do
if v.Name == "Waypoint" then
table.insert(npc_waypoints, v.CFrame)
end
end
local readytoQueue = false
local exited = false
local selectWaypoint = npc_waypoints[math.random(1, #npc_waypoints)]
followPath(npcClone, selectWaypoint)
print(CashoutQueue)
npcClone.Humanoid.MoveToFinished:Connect(function(reached)
if reached and wpIdx < #wps then
wpIdx += 1
npcClone.Humanoid:MoveTo(wps[wpIdx].Position)
else
if reached and readytoQueue == false then
readytoQueue = true
table.insert(CashoutQueue, npcClone)
moveQueue(Tycoon, CashoutQueue)
end
end
end)
path.Blocked:Connect(function(blockedWpIdx)
if blockedWpIdx > wpIdx then
followPath(npc_waypoints[1])
end
end)
end
return CustomerManager
I don’t know if I’m taking the right route to achieve what I want, I simply want a customer to walk to a location, then walk to the queue and then after a few seconds leave. If you have any advice that would be appriciated