The script is supposed to make the NPC follow player, (to kill him)
Script is supposed to make the NPC avoid obstacles and etc
but instead he just stays on same spot
Even other scripters couldnt help, what do i do
Are there any errors? Also, your code doesn’t really make sense, you should first pick the closest player and follow them, I am not sure why you’re looping through all the players every time.
Im doing it in the PlayerLoop because i want access to the humroot
to be able to compute it
Replace Dummy.Humanoid:MoveTo(waypoint) in line 25 with Dummy.Humanoid:MoveTo(waypoint.Position)
The PathWaypoint also has other properties like for example Action (Jump, walk) so you need to specify waypoint.Position
Ok so I have a little problem
Im trying to make a dummy pathfind its way to me and go around walls,avoid them,jump, etc.
right now he walks around things
but he just doesnt target me
This is the script
no errors.
sorry for confused images/double images i just really tired
That must be because it is in loops and it keeps recomputing the path but I’m not sure. The for loop with the path:GetWaypoints() should be correct. You could try declaring a function and then just move the NPC to a specific point for testing, for example like this (it’s basically like yours):
function npcPathfinding(npc, destination)
local hum = npc:WaitForChild("Humanoid")
local hrp = npc:WaitForChild("HumanoidRootPart")
local path = PFS:CreatePath()
path:ComputeAsync(hrp.Position, destination.Position)
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
hum:MoveTo(waypoint.Position)
-- if waypoint.Action == Enum.PathWaypointAction.Jump then
-- hum:ChangeState(Enum.HumanoidStateType.Jumping)
-- end
-- Could add above if he might not be jumping
hum.MoveToFinished:Wait()
end
Also thanks for editing the post I first thought the issue was that he couldn’t jump over things and walks around
In addition: from the script it seems like you want to make an enemy NPC that walks towards/attacks an enemy, right now he’s calculating a path between him and every player in the server in the for loop, I would instead get the magnitude between the NPC and the players and determine which player is the closest and then calculate a path to that player
I’ve just read that you have already explained all of that before sorry, to use the rootpart you could for example do
local nearestPlayer;
local shortestMagnitude;
for _, player in pairs(players) do
if magnitude < shortestMagnitude then
nearestPlayer = player
end
end
Thank you, i think i could fix it now i think
if i will be still have problems i could ask you again
if i will be having critical problems and you have discord we could talk in.
but now, thanks alot
Sure, add me if you want LeePha#4799
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.