Hello there! I am currently in the process of making a strategy game. I want to use pathfinding for my soldiers. Yet, for some reason after some time the pathfinding service just “breaks”. Video demonstration:
--ServerScript (Issue probably here)
game.ReplicatedStorage.UnitRemotes.MoveTo.OnServerEvent:Connect(function(plr, objectlist, pos)
for i, char in pairs(objectlist) do
print("that")
spawn(function()
local PathfindingService = game:GetService("PathfindingService")
local hum = char:WaitForChild("Humanoid")
local torso = char:WaitForChild("Torso")
local path = PathfindingService:CreatePath()
path:ComputeAsync(torso.Position, pos)
local waypoints = path:GetWaypoints()
for i, waypoint in pairs(waypoints) do
local brick = Instance.new("Part")
brick.Size = Vector3.new(1,1,1)
brick.Anchored = true
brick.Transparency = 0.5
brick.CanCollide = false
brick.Parent = workspace
brick.Position = waypoint.Position
brick.Name = "briko"
local Ignore = {}
for i, thing in pairs(workspace:GetChildren()) do
if thing:FindFirstChild("Humanoid") then
table.insert(Ignore, thing)
end
end
hum:MoveTo(waypoint.Position)
hum.MoveToFinished:Wait()
--[[
local ray = Ray.new(char.Torso.Position, (brick.Position - char.Torso.Position).Unit * 40)
local part, pos = workspace:FindPartOnRayWithIgnoreList(ray, Ignore)
if part then
if part.Name == "briko" then
hum:MoveTo(waypoint.Position)
print("success")
else
hum:MoveTo(waypoint.Position)
print("fail")
hum.MoveToFinished:Wait()
end
else
hum:MoveTo(waypoint.Position)
print("fail")
hum.MoveToFinished:Wait()
end
--]]
end
end)
end
end)