You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? I want to know why my npc is not following my player’s character
-
What is the issue? Include screenshots / videos if possible! The Npc i programed to follow players is not following them
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub? I have looked over my script and found nothing wrong with it
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local Npc = script.Parent
local NpcHumanoid = Npc:FindFirstChild("Humanoid")
local NpcHumanoidRootPart = Npc:FindFirstChild("HumanoidRootPart")
NpcHumanoidRootPart.Anchored = false
local NpcTorso = Npc:FindFirstChild("UpperTorso")
local AgentPrameters = {
AgentRadius = 5;
AgentHeight = 10;
AgentCanJump = true;
WayPointSpacing = 3;
Costs = {
BasePlate = 100;
Grass = 0
}
}
game.Players.PlayerAdded:Connect(function(Player)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild("Humanoid")
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
local PathFindingService = game:GetService("PathfindingService")
local Path = PathFindingService:CreatePath(AgentPrameters)
Path:ComputeAsync(NpcTorso.Position, HumanoidRootPart.Position)
if Path.Status == Enum.PathStatus.Success then
print("Path Status is a sucess!")
local Waypoints = Path:GetWaypoints()
for _,Waypoint in ipairs(Waypoints) do
local Node = Instance.new("Part")
Node.Shape = Enum.PartType.Ball
Node.Size = Vector3.new(0.6,0.4,0.6)
Node.Position = Waypoint.Position + Vector3.new(0,1,0)
Node.BrickColor = BrickColor.new("Earth green")
Node.Material = Enum.Material.Neon
Node.Anchored = true
Node.CanCollide = false
Node.Parent = game.Workspace
if Waypoint.Action == Enum.PathWaypointAction.Jump then
NpcHumanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
NpcHumanoid:MoveTo(Waypoint.Position)
NpcHumanoid.MoveToFinished:Wait(2)
end
else
print("Path status was not sucessfull path has been blocked")
Path.Blocked:Connect(function(BlockedWaypointIndex)
print(BlockedWaypointIndex .. "Is being Blocked")
Path:Check0cclusionAsync(NpcTorso.Position)
end)
Path.Unblocked:Connect(function(UnBlockedWaypointIndex)
print(UnBlockedWaypointIndex .. "Has been unblocked")
end)
end
end)
Hello, all so i’m trying to make a advanced pathfinding AI system for my game and i’m trying to make it follow the player when they join but the problem is AI is not following the players and are instead going to the workspace orgin point why is this happening? Thank you all for your help