-
What do you want to achieve? Keep it simple and clear! I want to make an AI that follows you and goes around obstacles.
-
What is the issue? Include screenshots / videos if possible! My script is not working. Script:
local Jenny = game.Workspace.JennyAnimated
local Humanoid = Jenny.Humanoid
local Humanoid2 = Jenny:WaitForChild(“Humanoid”)
local PFS = game:GetService(“PathfindingService”)
local Player = game.Players:FindFirstChildWhichIsA(“Player”) or game.Players.PlayerAdded:Wait()
local PlayerC = Player.Character or Player.CharacterAdded:Wait()
local PlayerHRP = PlayerC:WaitForChild(“HumanoidRootPart”)
print(PlayerHRP)
local Jenny = script.Parent
local Humanoid = Jenny.Humanoid
game.Workspace.BrownDoor.Hitbox.Touched:Connect(function(hit)
if hit.Parent.Name == (“BrownKey”) then
Jenny.HumanoidRootPart.JennysTheme2:Play()
while true do
local path = PFS:CreatePath()
path:ComputeAsync(Jenny.HumanoidRootPart.Position,PlayerHRP.Position)
local WPs = path:GetWaypoints()
for _,Waypoint in pairs(WPs) do
Jenny.Humanoid:MoveTo(Waypoint.Position)
end
wait()
end
end
end) -
What solutions have you tried so far? Did you look for solutions on the Developer Hub? I’ve tried putting this in the script: Jenny.Humanoid.MoveToFinished:Wait()
But that makes the AI walk incorrectly.
Please put triple backticks before and after scripts in your post so they are formatted properly.
One issue is that you have a while true do
about halfway through your script, which is fired by the BrownDoor.Hitbox.Touched
function. The issue is that once you start the while true do
loop it doesn’t end so the rest of the script doesn’t work.
Have you read the Pathfinding information pages in the create.roblox.com site. As the instruction in the #3 What solutions have you tried so far? section in your original post asks “Did you look for solutions on the Developer Hub?”.
Try using the Search tool up top and use ‘pathfinding following a player’ as a term to search in these forums?
I didn’t find any solutions on the dev hub.
What topic do you want me to search ‘pathfinding following a player’?
Just search all of them.
If you don’t get an answer that works try changing it to something slightly different like “NPC not following”. Get creative with the terms you use because people usually don’t write their topics down exactly the way you would.
I’m not sure I understand what you meant by “NPC not following”.
And I didn’t find any problem similar to mine.
An NPC is a Non Player Character.
I know that, I just didn’t quite understand what that code would do.
I hate to ask this, but could you try to fix my script? I’ll try to understand it after.