r/code • • May 11 '20

Halp pls! I need help with roblox code

i've tried many scripts and plugins and i still can't use pathfinding service. i tried this:

  1. local PathfindingService = game:GetService("PathfindingService")

  2. -- Variables for the zombie, its humanoid, and destination

  3. local chicken = game.Workspace.Chicken

  4. local humanoid = zombie.Humanoid

  5. local destination = game.Workspace.Nest

  6. -- Create the path object

  7. local path = PathfindingService:CreatePath()

  8. -- Compute the path

  9. path:ComputeAsync(zombie.HumanoidRootPart.Position, destination.PrimaryPart.Position)

  10. -- Get the path waypoints

  11. local waypoints = path:GetWaypoints()

  12. -- Loop through waypoints

  13. for _, waypoint in pairs(waypoints) do

  14. local part = Instance.new("Part")

  15. part.Shape = "Ball"

  16. part.Material = "Neon"

  17. part.Size = Vector3.new(0.6, 0.6, 0.6)

  18. part.Position = waypoint.Position

  19. part.Anchored = **true**
  20. part.CanCollide = **false**
  21. part.Parent = **game**.Workspace
  22. end

What's wrong? Did i forget something?

13 Upvotes

5 comments sorted by

1

u/Binau-01 May 11 '20

Can you provide some more context?

1

u/WarriorsTrash May 11 '20

i am trying to get a block (placeholder for a chicken) get to a nest(for now a single part each).

1

u/Binau-01 May 11 '20

Alright, what language, frameworks, plugins etc. are you using? Tell me a little more about the pathfindingService. Also what error are you getting?

1

u/WarriorsTrash May 11 '20

i'll import the code again, as i removed it from the game until i could get help fixing it. the plugins i used hadnt been updated, maybe that is why those didnt work. roblox uses lua, so there's the language.

1

u/WarriorsTrash May 11 '20

attempt to index 'nil' with Humanoid