NPC is able to climb with AgentCanClimb set to false

I have a feature in my game where customers will enter the store and walk around, looking for an item. When i tell the customer to walk to a random position, it will go straight there and climb the shelves with AgentCanClimb equal to false. How can i fix this and make the NPC take a reasonable path?


(I set the humanoid’s climbing StateEnabled to false as an attempt to fix this)

1 Like

You can make a part and randomise its position in the store, then check if its on a shelf, if it is, run the part-making process again until its on the ground, and make the npc move to that part.

Also the NPC is not climbing, but just stepping onto a brick. Not really climbing but close enough.

The issue is not that the position the NPC moves to is on the shelf, its that the NPC is making a path that goes over the shelf. I already have my positions in a table, and it picks a random one from that table.

Can I see the script your using?

1 Like
local SS = game:GetService("ServerStorage")
local Sounds = game:GetService("SoundService")
local CS = game:GetService("Chat")
local PFS = game:GetService("PathfindingService")
local TS = game:GetService("TweenService")
local customer = SS:WaitForChild("CustomerNPC")
local hum = customer:WaitForChild("Humanoid")
local animator = hum.Animator
local hrp = customer:WaitForChild("HumanoidRootPart")
local head = customer:WaitForChild("Head")

local thinkAnim = script.Think
local thinkTrack = animator:LoadAnimation(thinkAnim)

local positionsFolder = game.Workspace.CustomerLocations
local randFolder = positionsFolder.RandomSpots
local randPos = randFolder:GetChildren()

local path = PFS:CreatePath({
	AgentRadius = 2,
	AgentHeight = 5,
	AgentCanJump = false,
	AgentCanClimb = false,
	WaypointSpacing = 4,	
})

local function tweenPart(part, cframe, tweenTime)
	TS:Create(part, TweenInfo.new(tweenTime), {CFrame = cframe}):Play()
end

local function moveNPC(destination)
	hum:MoveTo(destination)

	-- Repeat check every timeout seconds to see if NPC reached destination
	while (customer.PrimaryPart.Position - destination).Magnitude > 1 do
		wait(5)
		hum:MoveTo(destination)
	end
	
	tweenPart(hrp, destination, 0.5)
end

local function chat(msg)
	CS:Chat(head, msg, Enum.ChatColor.White)
end

local function lookForItem()
	local count = math.random(2, #randPos)
	
	for i = 1, count do
		local posDecided = randPos[math.random(1, #randPos)]
	
		path:ComputeAsync(hrp.Position, posDecided.Position)
	
		for i, point in path:GetWaypoints() do
			hum:MoveTo(point.Position)
			hum.MoveToFinished:Wait()
		end
		
		wait()
		
		tweenPart(hrp, posDecided.CFrame, 0.5)
		
		thinkTrack:Play()
		
		wait(math.random(4, 10))
		thinkTrack:Stop()
	end
	
	return
end

while wait(math.random(5, 20)) do
	Sounds.Chime:Play()
	customer.Parent = game.Workspace
	hrp.CFrame = positionsFolder.SpawnPart.CFrame
	
	hrp:SetNetworkOwner(nil)
	
	lookForItem()
	
	moveNPC(positionsFolder.RingPart.Position)
end

very messy, i apologize

This is not the best way to do it, because it doesn’t even go around obstacles.

heres a better example you can use.

local Waypoints = path:GetWaypoints()

for i,waypoint in pairs(Waypoints) do
		Hum:MoveTo(waypoint.Position)
		Hum.MoveToFinished:Wait()
		Path:Destroy()
end

You use it here, so you can also use it in the function:

for i, point in path:GetWaypoints() do
			hum:MoveTo(point.Position)
			hum.MoveToFinished:Wait()
		end
1 Like

I have two functions for moving the NPC, and LookForItem is the only one that uses pathfinding.

Why not use it in the function?

1 Like

Good idea, ill change that. I’m not great at making clean code.

It seems the customers will try to climb the shelves less often, but they still do sometimes. @JAcoboiskaka1121

Try to place invisible walls inside the shelf themselves, so it would be acting less like a ladder, and more of a smooth part.

1 Like

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