Creating a Store/Restaurant Type Pathfinding?

Hi so i just recently decided to randomly click on that blue roblox icon sitting on my desktop after almost a year,

What I Want To Create:

I want to create a pathfinding system that can have customers walk in and out, Such as Work At A Pizza Place, i never really touched pathfinding and all i can find really is just “Horror Pathfinding” tutorials, Could anyone point me in a direction i can start at? Please and thank you.

I have tried setting waypoints to the shelves for the Customer to look at, So how can i add logic too it also like hey this item looks good let me pick it up, walk to the register and cash out. I assume look vectors can be useful in this anyways I hope this doesn’t look like me requesting for a script. Just a base I should start working on can help me a lot!

6 Likes

You could use Moveto, but it stops after 8 seconds so I recommend looping it.

5 Likes

I believe you are describing two types of NPC movement systems. The movement system the NPCs in Work at a Pizza Place use isn’t actually pathfinding, but is rather just telling the NPC where to walk using MoveTo(), a method that can be called on humanoids that makes them attempt to walk to the specified position. The second movement system for having NPCs walk to shelves sounds like it would use actual pathfinding. Pathfinding is simply determining the most logical path that an NPC would need to take to get from its current position to the destination. Since you’ve “never really touched pathfinding” I would recommend you follow this tutorial to get a general sense of how pathfinding works: Character Pathfinding. If you need help or have any general questions, you can always reply and I’d love to help.

2 Likes

Hey so i got a pretty good base going right now, but i have found an issue if a Customer is already looking at the shelf it should be set the attribute “Occupied” to true which it does. Although lets say 5 Customers spawn at once they still all Pathfind to that final destination, Let me record a video to help you understand.

Hopefully the video can help you visualize better.

	local waypoints = workspace.Waypoints:GetChildren()
	local despawn = workspace.Despawn:GetChildren()
	local randomWaypoint = math.random(1, #waypoints)
	local randomDespawn = math.random(1, #despawn)
	if waypoints[randomWaypoint]:GetAttribute("Occupied") == true then
		print("The shelves are occupied, deleting myself")
		NPC:Destroy()
		return
	end
	waypoints[randomWaypoint]:SetAttribute("Occupied", true)
	walkTo(LeaveStore)
	walkTo(waypoints[randomWaypoint])
	wait(5)
	walkTo(CashRegister)
	wait(math.random(1,3))
	print("Purchased Item Walking To Store Exit")
	walkTo(LeaveStore)
	wait(2)
	walkTo(despawn[randomDespawn])
	if NPC.HumanoidRootPart.Position == despawn[randomDespawn].Position then
		NPC:Destroy()
	end
end
-- Want to make it so it updates and says hey is this shelf occupied let me stop doing what im doing or find a new shelf to go to.
Patrol()``` Here is also my code, i assume i would do this in the moveTo function i have or in a heartbeat that checks if its occupied and find a shelf that isnt occupied? No clue.
3 Likes

So, is the waypoint that multiple NPCs go to’s “Occupied” attribute not getting set to true which causes multiple NPCs to go to that shelf?

4 Likes

Spawn them with a really short delay

3 Likes

Yeah, so basically if i have 8 Bob’s (Customer) as they spawn in they check to see if the shelf that they were assigned to example Shelf 1 is occupied by another Customer, if it is it’ll just use the Destroy function to delete itself, although thats fine I want to make it attempt to try and find another shelf that isn’t occupied example Shelf 2. There is also another issue with the multiple NPCs which is them going to an already occupied shelf because they spawned at the exact same time, Example John and Bob are going to Shelf 1 because they both spawned at the same time instead of John saying “Im already active at shelf 1 its occupied”, I assume to fix it is just make a way of detecting if its occupied in the moveTo function which is supplied then making the moveTo function a heartbeat or while loop.

	local path = PathFinding:CreatePath({
		AgentHeight = 6;
		AgentRadius = 1;
		AgentCanJump = true;
		AgentCanClimb = false;
		
		Costs = {
			Water = 100;
			DangerZone = math.huge
		}
	})
	
	path:ComputeAsync(NPC.HumanoidRootPart.Position, destination.Position)
	
	return path
end



local function walkTo(destination)
	local path = getPath(destination)
	
	if path.Status == Enum.PathStatus.Success then
		for index, waypoint in pairs(path:GetWaypoints()) do
			NPC.Humanoid.WalkSpeed = WalkSpeed
			Humanoid:MoveTo(waypoint.Position)
			Humanoid.MoveToFinished:Wait()
		end
	else
		Humanoid:MoveTo(destination.Position - (NPC.HumanoidRootPart.CFrame.LookVector * 10))
	end
end
2 Likes

Yeah i was thinking of this as an easy fix since i plan to make it OOP to spawn them in easier. But i want to still make it if its occupied it could try and find a new unoccupied shelf, if none are active it will have no choice but to self destruct lol.

2 Likes

You could assign line positions and make it check if it’s occupied at the entrance and once they enter the building they’re assigned a position in line, if that’s not what you’re looking for then make it assign a new shelf at the entrance

3 Likes

Oh YES that is so smart, like a trigger only for things with a NPC tag thank you so much. I appreciate the help i will try and implement it now.

2 Likes

Managed to get it working, took me a bit cause i had to rewrite it, thanks to all of you that helped!
Added a max tries after 3 tries the NPC decides to walk away if no shelfs are available.

2 Likes

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