You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Im making one of those restaurant games where npcs come and order. and im now working on the npc state system (idle, waiting, ordering, sitting, leaving). In this post im focusing only on on the “Sitting” state where after a npc got his order, would go to a random seat (that obviously should not be used by another npc. stay a set amount of seconds (thinking 20 seconds) then enters the leave state where he leaves and gets :destroy’d
What is the issue? Include screenshots / videos if possible!
Only issue i see is how to make the seat only for that npc only.
other than that just wanted to know whats the best way to make this. and get feedbacks on my idea!
What solutions have you tried so far? Did you look for solutions on the Creator Hub?
only make the seat models without the actual seat, and make the npc go to seat position once he reaches it the seat appears and the npc get tp to the chair (not sure if it could be buggy) then waits for set seconds and destroy the seat and tp him near the seat (like 2 studs to the right for example) and change his state to “leave”.
Hi, you can update the seat’s properties to the following:
Can Collide = false
Can Touch = false
Can Query = false
And then use a server script to seat the NPC by using the following example:
local seat = workspace.Seat
local npc = workspace.NPC
seat:Sit(npc:FindFirstChild("Humanoid"))
I do this in my own game.
The properties make it so that users cannot query the seat and therefore are unable to sit in it and only a server script can seat a humanoid, you can pair this with your creation and destruction of seats for minimal risks of users being able to take the seat (only way they would possibly do that from my knowledge is using exploits).
This is what i come up with;
It checks for all available seats, returns one randomly or nill if there isnt. and Then go to that seat :Sit like u showed me, waits for some time to “eat”, then un-sits and leaves. OR leaves directly if no seat was found.
-- Find a free seat
function QueueManager:TrySeat(npc)
local function AvailableSeat()
local Seats = workspace:WaitForChild("Seats")
local AvailableSeatss = {}
for _, v in pairs(Seats:GetChildren()) do
if v.Occupant == nil then
table.insert(AvailableSeatss, v)
end
end
if #AvailableSeatss > 0 then
return AvailableSeatss[math.random(1, #AvailableSeatss)]
end
return nil
end
-- move NPC to seat
local seat = AvailableSeat()
if seat then
NpcManager.WalkNPC_ToGoal(npc, seat, function()
seat:Sit(npc:FindFirstChild("Humanoid")) -- sit npc
npc:SetAttribute("State", "Seated")
task.delay(math.random(15, 30), function()
npc:FindFirstChild("Humanoid").Sit = false -- unsit npc
print("leavinnnnnnng")
QueueManager:Leave(npc)
end)
end)
else
-- no available seats, leave immediatly
QueueManager:Leave(npc)
end
end