Advertisement
Guest User

NPCClickMovementServer

a guest
Dec 2nd, 2024
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  2. local PathfindingService = game:GetService("PathfindingService")
  3.  
  4. local moveNPCEvent = ReplicatedStorage:WaitForChild("MoveNPCEvent")
  5.  
  6. moveNPCEvent.OnServerEvent:Connect(function(player, targetPosition)
  7. local npc = game.Workspace:FindFirstChild("Test") -- тут надо поменять test на имя своего нпс
  8. if npc then
  9. local humanoid = npc:FindFirstChildOfClass("Humanoid")
  10. local humanoidRootPart = npc:FindFirstChild("HumanoidRootPart")
  11. if humanoid and humanoidRootPart then
  12. local path = PathfindingService:CreatePath({
  13. AgentRadius = 2,
  14. AgentHeight = 5,
  15. AgentCanJump = true,
  16. AgentJumpHeight = 7.5,
  17. AgentMaxSlope = 45,
  18. AgentMaxStepHeight = 2,
  19. AgentCanClimb = false,
  20. AgentCanSwim = false,
  21. Costs = {}
  22. })
  23. path:ComputeAsync(humanoidRootPart.Position, targetPosition)
  24. path.Blocked:Connect(function()
  25. humanoid:MoveTo(targetPosition)
  26. end)
  27. humanoid:MoveTo(targetPosition)
  28. end
  29. end
  30. end)
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement