I did just that actually, but im pretty sure it doesn’t work due to it waiting till one pathfinding is done.
sure!
local Players = game:GetService("Players")
local PathFindingService = game:GetService("PathfindingService")
local Visuals = {}
local function ViewWayPoints(WP) -- pass the waypoints
for n, x in pairs(Visuals) do
x:Destroy()
end
local Att = Instance.new("Attachment")
local Bem = Instance.new("Beam")
Bem.FaceCamera = true
Att.Visible = true
for n, x in pairs(WP) do
local Point = Att:Clone()
Point.Parent = workspace.Terrain
Point.Position = x.Position
if n ~= 1 then
local Con = Bem:Clone()
Con.Attachment1 = Point
Con.Attachment0 = Visuals[n-1]
Con.Parent = Point
end
Visuals[n] = Point
end
end
Players.PlayerAdded:Connect(function(plr)
local Lord = game:GetService("Workspace"):WaitForChild("OurLordAndSavior")
local humanoid = Lord.Humanoid
for _, v in pairs(Lord:GetChildren()) do
if v:IsA("BasePart") then
v.CanCollide = false
v.Touched:Connect(function(hit)
if hit:IsA("BasePart") then
hit.Anchored = false
elseif Players:GetPlayerFromCharacter(hit.Parent) then
hit.Parent.Humanoid.Health = 0
end
end)
end
end
local function FindPlayer()
local NearestTarget
local AttackTarget
local AttackDist = 29
local maxDist = math.huge
for i, player in pairs(Players:GetPlayers()) do
if player.Character then
local target = player.Character
local Distance = (Lord.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
if Distance < maxDist then
NearestTarget = target
maxDist = Distance
AttackTarget = NearestTarget
AttackDist = Distance
return NearestTarget, AttackTarget
end
end
end
end
local function ToPath()
local NearestTarget, AttackTarget = FindPlayer()
local pathParams = {
["AgentRadius"] = 37.935,
["AgentHeight"] = 71.996,
["AgentCanJump"] = true
}
local path = PathFindingService:CreatePath(pathParams)
if NearestTarget then
path:ComputeAsync(Lord.HumanoidRootPart.Position, NearestTarget.HumanoidRootPart.Position)
end
if path.Status == Enum.PathStatus.Success then
if AttackTarget then
local Waypoints = path:GetWaypoints()
for i, waypoint in pairs(Waypoints) do
ViewWayPoints(Waypoints)
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait(2)
end
else
local Waypoints = path:GetWaypoints()
for i, waypoint in pairs(Waypoints) do
ViewWayPoints(Waypoints)
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait(2)
end
end
end
end
while true do
wait()
ToPath()
end
end)
Note: this is for the big boi, same script with the little one anyway
I believe coroutines will solve this issue. However I’m not too familiar with them… therefore I don’t know how to help you in using it in your script, just know the facts
Ah, thank you! " A coroutine is used to perform multiple tasks at the same time from within the same script." Im guessing the coroutine is used for the
how about the other two problems? since I’m stuck on them the most , I appreciate the big help though!
Looking back at the edit, you can use a blocked event to prevent it from getting stuck. Annoyingly as always, you’ll have to look for this event inside the path finding tutorial on the dev hub, there is a section about it!