### Full Pathfinding Script Example Source: https://github.com/grayzcale/simplepath/blob/main/docs/guides/getting-started.md A comprehensive script combining module import, agent/goal definition, event handling for path blocking, waypoint changes, errors, and continuous following. Includes visualization and initial path execution. ```lua --Import the module so you can start using it local ServerStorage = game:GetService("ServerStorage") local SimplePath = require(ServerStorage.SimplePath) --Define npc local Dummy = workspace.Dummy -- Define a part called "Goal" local Goal = workspace.Goal --Create a new Path using the Dummy local Path = SimplePath.new(Dummy) --Helps to visualize the path Path.Visualize = true --Dummy knows to compute path again if something blocks the path Path.Blocked:Connect(function() Path:Run(Goal) end) --If the position of Goal changes at the next waypoint, compute path again Path.WaypointReached:Connect(function() Path:Run(Goal) end) --Dummmy knows to compute path again if an error occurs Path.Error:Connect(function(errorType) Path:Run(Goal) end) Path:Run(Goal) ``` -------------------------------- ### Humanoid Pathfinding with Events - Lua Source: https://github.com/grayzcale/simplepath/blob/main/docs/examples/humanoid.md This Lua code demonstrates how to use the SimplePath module for humanoid navigation. It sets up pathfinding to a 'Goal' part and utilizes events like 'Reached', 'Blocked', 'WaypointReached', and 'Error' to recompute the path dynamically. Path visualization is enabled. ```lua --Import the module so you can start using it local ServerStorage = game:GetService("ServerStorage") local SimplePath = require(ServerStorage.SimplePath) --Define npc local Dummy = workspace.Dummy -- Define a part called "Goal" local Goal = workspace.Goal --Create a new Path using the Dummy local Path = SimplePath.new(Dummy) --Helps to visualize the path Path.Visualize = true --Compute a new path every time the Dummy reaches the goal part Path.Reached:Connect(function() Path:Run(Goal) end) --Dummy knows to compute path again if something blocks the path Path.Blocked:Connect(function() Path:Run(Goal) end) --If the position of Goal changes at the next waypoint, compute path again Path.WaypointReached:Connect(function() Path:Run(Goal) end) --Dummmy knows to compute path again if an error occurs Path.Error:Connect(function(errorType) Path:Run(Goal) end) Path:Run(Goal) ``` -------------------------------- ### Humanoid Continuous Pathfinding with Loop - Lua Source: https://github.com/grayzcale/simplepath/blob/main/docs/examples/humanoid.md This Lua code snippet shows how to continuously compute a path for a humanoid using the SimplePath module within a `while true` loop. It directs the humanoid towards a 'Goal' part and enables path visualization. This method ensures the humanoid constantly attempts to reach the goal. ```lua --Import the module so you can start using it local ServerStorage = game:GetService("ServerStorage") local SimplePath = require(ServerStorage.SimplePath) --Define npc local Dummy = workspace.Dummy -- Define a part called "Goal" local Goal = workspace.Goal --Create a new Path using the Dummy local Path = SimplePath.new(Dummy) --Helps to visualize the path Path.Visualize = true while true do Path:Run(Goal) end ``` -------------------------------- ### Lua: SimplePath Non-Humanoid Pathfinding with Waypoint Reached Source: https://github.com/grayzcale/simplepath/blob/main/docs/examples/non-humanoid.md This Lua script demonstrates basic pathfinding for a non-humanoid model using the SimplePath module. It includes a tweening function to animate the model's movement to each waypoint and handles the 'Reached' and 'WaypointReached' events to update the model's position and continue the path. ```lua local TweenService = game:GetService("TweenService") local ServerStorage = game:GetService("ServerStorage") local SimplePath = require(ServerStorage.SimplePath) local Model = workspace.Model local Goal = workspace.Goal local Path = SimplePath.new(Model) local function tween(part, destination) local tweenBase = TweenService:Create(part, TweenInfo.new(0.07), {Position = destination + Vector3.new(0, 0.5, 0)}) tweenBase:Play() tweenBase.Completed:Wait() end Path.Visualize = true --Tween model to final waypoint when reached Path.Reached:Connect(function(model, finalWaypoint) tween(model.PrimaryPart, finalWaypoint.Position) end) --Call Path:Run() at the end of the event to indicate the end of movement for the current waypoint Path.WaypointReached:Connect(function(model, lastWaypoint, nextWaypoint) tween(model.PrimaryPart, nextWaypoint.Position) Path:Run() -- Note: This should likely be Path:Run(Goal) to continue to the next waypoint if Goal is not the final destination. end) Path:Run(Goal) ``` -------------------------------- ### Lua: SimplePath Non-Humanoid Pathfinding Loop Source: https://github.com/grayzcale/simplepath/blob/main/docs/examples/non-humanoid.md This Lua script demonstrates a continuous pathfinding loop for non-humanoid models. It sets the model's position directly at waypoints without explicit tweening and repeatedly calls 'Path:Run(Goal)' within a loop to ensure the model constantly attempts to find and follow a path to the goal. ```lua local TweenService = game:GetService("TweenService") local ServerStorage = game:GetService("ServerStorage") local SimplePath = require(ServerStorage.SimplePath) local Model = workspace.Model local Goal = workspace.Goal local Path = SimplePath.new(Model) Path.Visualize = true Path.Reached:Connect(function(model, finalWaypoint) model.PrimaryPart.Position = finalWaypoint.Position + Vector3.new(0, 0.5, 1) end) Path.WaypointReached:Connect(function(model, lastWaypoint, nextWaypoint) model.PrimaryPart.Position = nextWaypoint.Position + Vector3.new(0, 0.5, 1) end) while true do Path:Run(Goal) ttask.wait() end ``` -------------------------------- ### Lua: SimplePath Non-Humanoid Pathfinding with Error Handling Source: https://github.com/grayzcale/simplepath/blob/main/docs/examples/non-humanoid.md This Lua script showcases advanced pathfinding for non-humanoid models, including handling path blockages and errors. It uses a tweening function for smooth movement and reconnects to the 'Run' function when the path is blocked or an error occurs, ensuring continuous movement towards the goal. ```lua local TweenService = game:GetService("TweenService") local ServerStorage = game:GetService("ServerStorage") local SimplePath = require(ServerStorage.SimplePath) local Model = workspace.Model local Goal = workspace.Goal local Path = SimplePath.new(Model) local function tween(part, destination) local tweenBase = TweenService:Create(part, TweenInfo.new(0.07), {Position = destination + Vector3.new(0, 0.5, 0)}) tweenBase:Play() tweenBase.Completed:Wait() end Path.Visualize = true --If the path is blocked Path.Blocked:Connect(function() Path:Run(Goal) end) --In case of an error Path.Error:Connect(function() Path:Run(Goal) end) Path.Reached:Connect(function(model, finalWaypoint) tween(model.PrimaryPart, finalWaypoint.Position) Path:Run(Goal) end) Path.WaypointReached:Connect(function(model, lastWaypoint, nextWaypoint) tween(model.PrimaryPart, nextWaypoint.Position) Path:Run(Goal) end) Path:Run(Goal) ``` -------------------------------- ### Initialize Pathfinding Agent and Goal Source: https://github.com/grayzcale/simplepath/blob/main/docs/guides/getting-started.md Defines the NPC (Dummy) and the target destination (Goal) for pathfinding. Creates a new Path object associated with the Dummy, which is intended to be created only once per agent. ```lua --Define npc local Dummy = workspace.Dummy --Define a part called "Goal" local Goal = workspace.Goal --Create a new Path using the Dummy local Path = SimplePath.new(Dummy) ``` -------------------------------- ### Run Pathfinding to Goal Source: https://github.com/grayzcale/simplepath/blob/main/docs/guides/getting-started.md Initiates the pathfinding process for the Dummy to reach the Goal. This is the primary function to make the NPC move along a computed path. ```lua Path:Run(Goal) ``` -------------------------------- ### Import SimplePath Module Source: https://github.com/grayzcale/simplepath/blob/main/docs/guides/getting-started.md Imports the SimplePath module from ServerStorage, which is required to use its pathfinding functionalities. Assumes the module is placed in ServerStorage. ```lua --Import the module so you can start using it local ServerStorage = game:GetService("ServerStorage") local SimplePath = require(ServerStorage.SimplePath) ``` -------------------------------- ### SimplePath Pathfinding with Loops in Lua Source: https://github.com/grayzcale/simplepath/blob/main/docs/guides/getting-started.md This snippet demonstrates how to initialize and use SimplePath for pathfinding within a continuous loop. It requires importing the SimplePath module, defining the NPC and goal, and then repeatedly calling the Path:Run() method. The Path:Run() function automatically handles yielding, making it suitable for loop-based execution. ```lua --Import the module so you can start using it local ServerStorage = game:GetService("ServerStorage") local SimplePath = require(ServerStorage.SimplePath) --Define npc local Dummy = workspace.Dummy -- Define a part called "Goal" local Goal = workspace.Goal --Create a new Path using the Dummy local Path = SimplePath.new(Dummy) --Helps to visualize the path Path.Visualize = true while true do Path:Run(Goal) end ``` -------------------------------- ### Run Pathfinding Computation Source: https://github.com/grayzcale/simplepath/blob/main/docs/api-reference.md Initiates the pathfinding computation to a target. Returns true on success, false on failure, triggering the Error event. It includes automatic yielding for consecutive calls within a time variance. ```Lua local success = Path:Run(targetPartOrPosition) ``` -------------------------------- ### Handle Reached Event for Continuous Following Source: https://github.com/grayzcale/simplepath/blob/main/docs/guides/getting-started.md Connects to the Path.Reached event, which fires when the Dummy successfully reaches the Goal. By calling Path:Run(Goal) within this event, the Dummy will continuously follow the Goal even after reaching it. ```lua --Compute a new path every time the Dummy reaches the goal part Path.Reached:Connect(function() Path:Run(Goal) end) ``` -------------------------------- ### Handle Path Blocked Event Source: https://github.com/grayzcale/simplepath/blob/main/docs/guides/getting-started.md Connects to the Path.Blocked event, which fires when an obstacle obstructs the current path. It recomputes the path by calling Path:Run(Goal) to allow the Dummy to navigate around the obstruction. ```lua --Dummy knows to compute path again if something blocks the path Path.Blocked:Connect(function() Path:Run(Goal) end) ``` -------------------------------- ### Handle Waypoint Reached Event Source: https://github.com/grayzcale/simplepath/blob/main/docs/guides/getting-started.md Connects to the Path.WaypointReached event. This is useful for dynamic goals, as it recomputes the path when the Dummy reaches a waypoint, ensuring it follows the Goal's potentially updated position. ```lua --If the position of Goal changes at the next waypoint, compute path again Path.WaypointReached:Connect(function() Path:Run(Goal) end) ``` -------------------------------- ### Enable Path Visualization Source: https://github.com/grayzcale/simplepath/blob/main/docs/guides/getting-started.md Sets the Path.Visualize property to true. This enables the visual representation of the computed path's waypoints, which is helpful for debugging and understanding the pathfinding process. ```lua --Helps to visualize the path Path.Visualize = true ``` -------------------------------- ### Handle Path Error Event Source: https://github.com/grayzcale/simplepath/blob/main/docs/guides/getting-started.md Connects to the Path.Error event, which triggers if the path becomes untraversable or the target is unreachable. It attempts to recompute the path by calling Path:Run(Goal) to resolve the error. ```lua --Dummmy knows to compute path again if an error occurs Path.Error:Connect(function(errorType) Path:Run(Goal) end) ``` -------------------------------- ### Path Error Event Source: https://github.com/grayzcale/simplepath/blob/main/docs/api-reference.md Fired when any pathfinding error occurs. It returns the specific error type and a string description of the error. ```Lua Path.Error:Connect(function(errorType, errorMessage) print("Pathfinding error: " .. errorMessage) end) ``` -------------------------------- ### Path Blocked Event Source: https://github.com/grayzcale/simplepath/blob/main/docs/api-reference.md Fired when the path is blocked. It provides the agent model and the PathWaypoint where the blockage occurred, indicating the agent cannot proceed. ```Lua Path.Blocked:Connect(function(agent, blockedWaypoint) print("Path blocked at waypoint index: " .. blockedWaypoint.Index) end) ``` -------------------------------- ### Path Reached Event Source: https://github.com/grayzcale/simplepath/blob/main/docs/api-reference.md Fired when the agent successfully reaches its destination. It provides the agent model and the final PathWaypoint object. ```Lua Path.Reached:Connect(function(agent, finalWaypoint) print("Agent reached destination.") end) ``` -------------------------------- ### Connect to Path Error Event Source: https://github.com/grayzcale/simplepath/blob/main/docs/api-reference.md This Lua code snippet demonstrates how to connect a function to the Path.Error event. The connected function will be executed whenever a ComputationError occurs, allowing for specific error handling logic. ```Lua Path.Error:Connect(function(errorType) if errorType == SimplePath.ErrorType.ComputationError then --code (1) end end) ``` -------------------------------- ### Path Status and Last Error Source: https://github.com/grayzcale/simplepath/blob/main/docs/api-reference.md Retrieves the current status and the last error encountered by the Pathfinding system. The Status is always Idle for non-humanoids, indicating manual handling is required. LastError returns the specific error type if pathfinding fails. ```Lua local currentStatus = Path.Status local lastError = Path.LastError ``` -------------------------------- ### Destroy Path Object Source: https://github.com/grayzcale/simplepath/blob/main/docs/api-reference.md Cleans up and destroys the Path object, releasing associated resources. This is a standard method for managing pathfinding instances. ```Lua Path:Destroy() ``` -------------------------------- ### Path Stopped Event Source: https://github.com/grayzcale/simplepath/blob/main/docs/api-reference.md Fired after the Path:Stop() method is called. This event is intended for humanoid navigation. ```Lua Path.Stopped:Connect(function(agent) print("Path stopped for agent.") end) ``` -------------------------------- ### Waypoint Reached Event Source: https://github.com/grayzcale/simplepath/blob/main/docs/api-reference.md Fired each time the agent arrives at a PathWaypoint. It returns the agent, the last waypoint, and the next waypoint. This is crucial for non-humanoid pathfinding and has a stability note for the second-to-last waypoint with Humanoids. ```Lua Path.WaypointReached:Connect(function(agent, lastWaypoint, nextWaypoint) print("Agent reached waypoint.") end) ``` -------------------------------- ### Stop Pathfinding Navigation Source: https://github.com/grayzcale/simplepath/blob/main/docs/api-reference.md Halts the current pathfinding navigation if the Path is active. This method fires the Stopped event and is intended for humanoids only. Non-humanoid pathfinding requires manual stopping. ```Lua Path:Stop() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.