Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make an NPC move from block to block?

Hello, I'm currently working on a camping game and i need help with the NPC movement. I've already looked at all the tutorials on yt but they didnt work. If you know an answer, please let me know.

1 comment

0

2 answers

I posted a similar question in the previous questions, look what I used, maybe it helps.

The NPC moves on certain declared areas and loop every time it reaches the target.

local NPC = script.Parent.Judoon -- Name Npc Here
while true do
wait()
NPC.Humanoid:MoveTo(script.Parent.JudoonWallX.Position) ' Name Wall Here'
NPC.Humanoid.MoveToFinished:wait()
wait(0)
NPC.Humanoid:MoveTo(script.Parent.JudoonWallZ.Position) ' Name Another Wall'
NPC.Humanoid.MoveToFinished:wait()
end

It should stop when it reaches the target, compared to the one above, when the loop repeats.

Credit: AcrylixDev

local NPC = script.Parent.Judoon -- The name of the NPC is here.
local debounce = false
while true do
wait()
if debounce == false then
debounce = true
NPC.Humanoid:MoveTo(script.Parent.JudoonWallX.Position)
NPC.Humanoid.MoveToFinished:wait()
local debounce = false
end
end


3 comments

0

I answered that very qqeustio.

0

The second script you posted is my answer to help you, please give credits to me for it.

0

ok, please tell me how to do this. I changed the answer.

Here's a script for you:

local dest1 = workspace.Destanation1
local npc = workspace.Dummy --Change this to preferred NPC.
local humanoid = npc:FindFirstChild("Humanoid")
local service = game:GetService("PathfindingService")

local path = service:FindPathAsync(npc.Torso.Position,dest1.Position)
local points = path:GetWaypoints()

for key, value in pairs(points) do
	wait(0.5) -- Change it to your preferred time
	local part = Instance.new("Part")
	part.Parent = workspace
	part.Anchored = true
	part.CanCollide = false
	part.Position = value.Position
	part.Size = Vector3.new(1,1,1)
	part.Transparency = 0 --Change transparency lol
	humanoid.WalkToPoint = part.Position
end

This should help! This script also gets the NPC to navigate around or past walls. Hope this helps!

2 comments

0

I'm pretty sure that's the old Pathfinding service and there's a new one, if not then I must be hallucinating.

0

@AcrylixDev It's not the old pathfinding service. This was coded all by me.

This discussion is preserved as it was. New answers, comments, and votes are closed.