I used this script from the roblox blog on PathFinding:
-- In Script in ServerScriptService
local pathfindingService = game:GetService("PathfindingService")
local pointModel = Instance.new("Model")
pointModel.Name = "Points"
pointModel.Parent = game.Workspace
function visualizePath(path)
-- clear old path visualization
for _, point in pairs(pointModel:GetChildren()) do
point:Destroy()
end
-- calculate new visualization
local points = path:GetPointCoordinates()
for _, point in pairs(points) do
local part = Instance.new("Part")
part.Parent = pointModel
part.FormFactor = Enum.FormFactor.Custom
part.Size = Vector3.new(1,1,1)
part.Position = point
part.Anchored = true
part.CanCollide = false
end
end
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(player, target)
local start = player.Character.Torso.Position
local path = pathfindingService:ComputeRawPathAsync(start, target, 500)
visualizePath(path)
-- Check to see if the path was computed correctly
if path.Status == Enum.PathStatus.FailStartNotEmpty or path.Status == Enum.PathStatus.FailFinishNotEmpty then
print("Compute failed")
return {}
end
return path:GetPointCoordinates()
end
And it is not doing anything in-game. Is there something I'm doing wrong? I have it as a script in ServerScriptService.
