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.
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
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!