Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make an NPC move from block to block?

Asked by 4 years ago

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.

0
try watching this video: https://www.youtube.com/watch?v=9snIBGqAiEM NSMascot 113 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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


0
I answered that very qqeustio. AcrylixDev 119 — 4y
0
The second script you posted is my answer to help you, please give credits to me for it. AcrylixDev 119 — 4y
0
ok, please tell me how to do this. I changed the answer. darkeyescr 7 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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!

0
I'm pretty sure that's the old Pathfinding service and there's a new one, if not then I must be hallucinating. AcrylixDev 119 — 4y
0
@AcrylixDev It's not the old pathfinding service. This was coded all by me. diorlandripp 4 — 4y

Answer this question