|
| 15 Aug 2014 08:38 PM |
--Pathfinding Service local pfc = game:GetService("PathfindingService") local pointHolder = Instance.new("Model", Workspace) pointHolder.Name = "Points"
--Show Path function showPath(path) --clear old path for _, point in pairs(pointHolder:GetChildren()) do point:destroy() end --show new path local points = path:GetPointCoordinates() for _, point in pairs(points) do local part = Instance.new("Part", pointHolder) part.FormFactor = Enum.FormFactor.Custom part.Size = Vector3.new(1, 1, 1) part.Position = point part.Anchored = true part.CanCollide = false end end
local PathFinder = game.Workspace.PathFinder
local followingPath = false
function move() if not followingPath then followingPath = true --Calculate Path local points = pfcFunc("Start", "End") for _, point in pairs(points) do print("moving to: ", point) PathFinder.Humanoid.WalkToPoint = point -- Dont move until close enough to current point repeat distance = (point - PathFinder.Torso.Position).magnitude wait() until distance < 3 end followingPath = false end end
script.Parent.Touched:connect(move)
function pfcFunc(start, finish) print(start, finish) local start = game.Workspace:FindFirstChild(start).Position target = game.Workspace:FindFirstChild(finish).Position local path = pfc:ComputeRawPathAsync(start, target, 500) showPath(path) if path.Status == Enum.PathStatus.FailStartNotEmpty or path.Status == Enum.PathStatus.FailFinishNotEmpty then print("Compute Failed") return { } end end
Output:
Start End 20:27:38.997 - Workspace.Start.Script:37: bad argument #1 to 'pairs' (table expected, got nil) 20:27:38.998 - Script 'Workspace.Start.Script', Line 37 20:27:38.998 - Stack End
May anyone explain the problem and how to fix it please? |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 15 Aug 2014 08:40 PM |
before the for loop, check if it can find a path.
if YOUR COMPUTERAWASYNC.Status == Enum.PathStatus.Success then |
|
|
| Report Abuse |
|
|
|
| 15 Aug 2014 08:42 PM |
This:
function move() if not followingPath then followingPath = true --Calculate Path local points = pfcFunc("Start", "End") if path.Status == Enum.PathStatus.Success then for _, point in pairs(points) do print("moving to: ", point) PathFinder.Humanoid.WalkToPoint = point -- Dont move until close enough to current point repeat distance = (point - PathFinder.Torso.Position).magnitude wait() until distance < 3 end end followingPath = false end end |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
| |
|
|
| 15 Aug 2014 08:45 PM |
Sadly got the same error. :/ Just different line
|
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 15 Aug 2014 08:45 PM |
| try printing (path[1]) just to see what it says. |
|
|
| Report Abuse |
|
|
|
| 15 Aug 2014 08:46 PM |
Nevermind. :D Forgot to add:
return path:GetPointCoordinates()
At the end.. :D |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
| |
|
|
| 15 Aug 2014 08:48 PM |
| Yea, except it doesn't got to the block, it goes just shy of the last point, and not to the position of the set block. D: |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 15 Aug 2014 08:49 PM |
| Because you do until distance < 3, which makes it stop 3 studs before the point. Change it to something like distance < 0.5 or something. |
|
|
| Report Abuse |
|
|
|
| 15 Aug 2014 08:50 PM |
| D: Did 0.5 and it just went to the first point and stopped. :( |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 15 Aug 2014 08:52 PM |
| change v to v + the character's torso's lookvector then do < 2 |
|
|
| Report Abuse |
|
|
|
| 15 Aug 2014 08:54 PM |
repeat distance = (point + PathFinder.Torso.Position).magnitude wait() until distance < 2
So this?
Nope still first block and stops. D: |
|
|
| Report Abuse |
|
|
|
| 15 Aug 2014 08:55 PM |
So changed to this:
repeat distance = (point - PathFinder.Torso.Position).magnitude print(math.floor(distance)) wait() until distance <= 2
and it outputs "2" but doesn't move. D: |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 15 Aug 2014 08:56 PM |
for _, point in pairs(points) do x = point + PathFinder.Torso.CFrame.lookVector PathFinder.Humanoid.WalkToPoint = x repeat distance = (x-PathFinder.Torso.Position).magnitude wait() until distance < 2 |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 15 Aug 2014 08:57 PM |
actually no, do something like this for _, point in pairs(points) do x = point PathFinder.Humanoid.WalkToPoint = x wait(1) x = point + PathFinder.Torso.CFrame.lookVector PathFinder.Humanoid.WalkToPoint = x repeat distance = (x-PathFinder.Torso.Position).magnitude wait() until distance < 2 |
|
|
| Report Abuse |
|
|
|
| 15 Aug 2014 09:00 PM |
He did weird things.. So current script: (Changed..)
--Pathfinding Service local pfc = game:GetService("PathfindingService") local pointHolder = Instance.new("Model", Workspace) pointHolder.Name = "Points" local path = nil local PathFinder = game.Workspace.PathFinder
--Show Path function showPath(path) --clear old path for _, point in pairs(pointHolder:GetChildren()) do point:destroy() end --show new path local points = path:GetPointCoordinates() for _, point in pairs(points) do local part = Instance.new("Part", pointHolder) part.FormFactor = Enum.FormFactor.Custom part.Size = Vector3.new(1, 1, 1) part.Position = point part.Anchored = true part.CanCollide = false part.Touched:connect(function() part:remove() end) end end
local followingPath = false
function move() if not followingPath then followingPath = true --Calculate Path local points = pfcFunc("Start", "End") for _, point in pairs(points) do print("moving to: ", point) PathFinder.Humanoid.WalkToPoint = point -- Dont move until close enough to current point local i = 0 repeat distance = (point - PathFinder.Torso.Position).magnitude i = i + 1 print(i, math.floor(distance)) wait() until math.floor(distance) <= 2 i = 0 end followingPath = false end end
script.Parent.Touched:connect(move)
function pfcFunc(start, finish) print(start, finish) local start = game.Workspace:FindFirstChild(start).Position target = game.Workspace:FindFirstChild(finish).Position path = pfc:ComputeRawPathAsync(start, target, 500) showPath(path) if path.Status == Enum.PathStatus.FailStartNotEmpty or path.Status == Enum.PathStatus.FailFinishNotEmpty then print("Compute Failed") return { } end return path:GetPointCoordinates() end
He still stops just shy of that last point before the end block. D: |
|
|
| Report Abuse |
|
|