You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Perfect PathFinding GUI
What is the issue? Include screenshots / videos if possible!
My Humanoid doesn’t avoid obstacles, or walk the right way.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Yes, i did search, but it didnt help.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local function Navigate()
local ending=waypoints[#waypoints]
local path=service:CreatePath({
AgentRadius=4,
AgentHeight=10,
AgentCanClimb=true,
AgentCanJump=true
})
path:ComputeAsync(root.Position, ending.Position)
local ways=path:GetWaypoints()
for i,v in ipairs(waypoints) do
hum:MoveTo(v.Position)
hum.MoveToFinished:Wait()
end
hum.MoveToFinished:Wait()
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
works, but now it doesnt start from the starting point, but starts from our position
local plr=game:GetService("Players").LocalPlayer
local char=plr.Character or plr.CharacterAdded:Wait()
local hum=char.Humanoid
local root=char.HumanoidRootPart
local service=game:GetService("PathfindingService")
local mouse=plr:GetMouse()
local waypoints={}
local function AddWaypoint()
local point=Instance.new("Part", game.Workspace)
point.Name="WP88871"
point.Position=root.Position
point.Anchored=true
point.Transparency=0.7
point.CanCollide=false
point.Size=Vector3.new(1, 0, 1, 0)
table.insert(waypoints, point)
end
local function Navigate()
local ending=waypoints[#waypoints]
local path=service:CreatePath({
AgentRadius=4,
AgentHeight=10,
AgentCanClimb=true,
AgentCanJump=true
})
path:ComputeAsync(root.Position, ending.Position)
local ways=path:GetWaypoints()
for i,v in ways do
hum:MoveTo(v.Position)
hum.MoveToFinished:Wait()
end
hum.MoveToFinished:Wait()
end
local function RemovePoints()
table.clear(waypoints)
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name=="WP88871" and v:IsA("BasePart") then
v:Remove()
end
end
end
local function ClickFind()
local tool=Instance.new("Tool", plr.Backpack)
tool.RequiresHandle=false
tool.Name="Click for Waypoint"
tool.ToolTip="e"
tool.Activated:Connect(function()
local wp=Instance.new("Part", game.Workspace)
wp.Name="WP88871"
wp.Size=Vector3.new(1, 0, 1, 0)
wp.Position=mouse.Hit.p
wp.Anchored=true
wp.Transparency=0.7
wp.CanCollide=false
table.insert(waypoints, wp)
end)
end
add.MouseButton1Click:Connect(AddWaypoint)
go.MouseButton1Click:Connect(Navigate)
remove.MouseButton1Click:Connect(RemovePoints)
click.MouseButton1Click:Connect(ClickFind)
I’ve just tested out the thing you recommended, and i placed 3 points:
start
behind obstacle
on obstacle(end)
and it didnt go through the behind obstacle point. any fixes?
ocal plr=game:GetService("Players").LocalPlayer
local char=plr.Character or plr.CharacterAdded:Wait()
local hum=char.Humanoid
local root=char.HumanoidRootPart
local service=game:GetService("PathfindingService")
local mouse=plr:GetMouse()
local waypoints={}
local function AddWaypoint()
local point=Instance.new("Part", game.Workspace)
point.Name="WP88871"
point.Position=root.Position
point.Anchored=true
point.Transparency=0.7
point.CanCollide=false
point.Size=Vector3.new(1, 0, 1, 0)
table.insert(waypoints, point)
end
local function Navigate()
local start=waypoints[1]
local ending=waypoints[#waypoints]
local path=service:CreatePath({
AgentRadius=4,
AgentHeight=10,
AgentCanClimb=true,
AgentCanJump=true
})
path:ComputeAsync(start.Position, ending.Position)
local ways=path:GetWaypoints()
for i,v in ways do
hum:MoveTo(v.Position)
hum.MoveToFinished:Wait()
end
hum.MoveToFinished:Wait()
end
local function RemovePoints()
table.clear(waypoints)
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name=="WP88871" and v:IsA("BasePart") then
v:Remove()
end
end
end
local function ClickFind()
local tool=Instance.new("Tool", plr.Backpack)
tool.RequiresHandle=false
tool.Name="Click for Waypoint"
tool.Activated:Connect(function()
local wp=Instance.new("Part", game.Workspace)
wp.Name="WP88871"
wp.Size=Vector3.new(1, 0, 1, 0)
wp.Position=mouse.Hit.p
wp.Anchored=true
wp.Transparency=0.7
wp.CanCollide=false
table.insert(waypoints, wp)
end)
end
add.MouseButton1Click:Connect(AddWaypoint)
go.MouseButton1Click:Connect(Navigate)
remove.MouseButton1Click:Connect(RemovePoints)
click.MouseButton1Click:Connect(ClickFind)
The Navigate function only checks the first and last waypoint. You need another loop through each waypoint to visit each one:
for index, waypoint in waypoints do
local nextWaypoint = waypoints[index + 1]
if not nextWaypoint then
return -- We have finished pathfinding
end
path:ComputeAsync(waypoint.Position, nextWaypoint.Position))
... rest of the code ...
Also, you don’t need to do :CreatePath each time in Navigate unless you are changing the parameters. You should move it outside the function.
Also, how are you writing the script? Have you intentionally removed the indentation and spacing? It’s very difficult to read.
-- More difficult to read
local myValue=5
-- Easier to read
local myValue = 5
-- Difficult to read
local function Hello()
print("Hi!")
if myValue > 5 then
print("Hello!")
else
print("Hey!")
end
end
-- Easier to read
local function Hello()
print("Hi!")
if myValue > 5 then
print("Hello!")
else
print("Hey!")
end
end
local plr=game:GetService("Players").LocalPlayer
local char=plr.Character or plr.CharacterAdded:Wait()
local hum=char.Humanoid
local root=char.HumanoidRootPart
local service=game:GetService("PathfindingService")
local mouse=plr:GetMouse()
local waypoints={}
local function AddWaypoint()
local point=Instance.new("Part", game.Workspace)
point.Name="WP88871"
point.Position=root.Position
point.Anchored=true
point.Transparency=0.7
point.CanCollide=false
point.Size=Vector3.new(1, 0, 1, 0)
table.insert(waypoints, point)
end
local function Navigate()
local start=waypoints[1]
local ending=waypoints[#waypoints]
local path=service:CreatePath({
AgentRadius=4,
AgentHeight=10,
AgentCanClimb=true,
AgentCanJump=true
})
path:ComputeAsync(start.Position, ending.Position)
local ways=path:GetWaypoints()
for index, waypoint in waypoints do
local nextWaypoint = waypoints[index + 1]
hum:MoveTo(nextwaypoint)
if not nextWaypoint then
return -- We have finished pathfinding
end
end
hum.MoveToFinished:Wait()
end
local function RemovePoints()
table.clear(waypoints)
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name=="WP88871" and v:IsA("BasePart") then
v:Remove()
end
end
end
local function ClickFind()
local tool=Instance.new("Tool", plr.Backpack)
tool.RequiresHandle=false
tool.Name="Click for Waypoint"
tool.Activated:Connect(function()
local wp=Instance.new("Part", game.Workspace)
wp.Name="WP88871"
wp.Size=Vector3.new(1, 0, 1, 0)
wp.Position=mouse.Hit.p
wp.Anchored=true
wp.Transparency=0.7
wp.CanCollide=false
table.insert(waypoints, wp)
end)
end
add.MouseButton1Click:Connect(AddWaypoint)
go.MouseButton1Click:Connect(Navigate)
remove.MouseButton1Click:Connect(RemovePoints)
click.MouseButton1Click:Connect(ClickFind)