I’m trying to make a function happen when a robot I made reaches the end a path. Here’s the code.
function calculate(thing)
local highlight = Instance.new("Highlight")
highlight.Parent = thing
warn(thing.Name.." is the target.")
local raycastresult = workspace:Raycast(thing.Position, Vector3.new(0,-100,0))
local params = RaycastParams.new()
params.FilterDescendantsInstances = {thing.Parent}
if raycastresult then
calcpath:ComputeAsync(script.Parent.HumanoidRootPart.Position, raycastresult.Position, params)
end
--calcpath:ComputeAsync(script.Parent.HumanoidRootPart.Position, workspace.Target.Position)
script.Parent.Target.Value = thing.Name
warn("Calculated!")
if calcpath.Status == Enum.PathStatus.Success then
local ways = calcpath:GetWaypoints()
warn("Where to go?")
for i, point in ipairs(ways) do
if i == #ways then return end
warn("I know where to go, can I get there?")
Humanoid:MoveTo(point.Position)
print("Go!")
local pathview = Instance.new("Part")
pathview.Name = "PathfindTrack"
pathview.Size = Vector3.new(1,0,1)
pathview.BrickColor = BrickColor.new("Electric blue")
pathview.Parent = workspace
pathview.Position = point.Position
pathview.Material = Enum.Material.Neon
pathview.Anchored = true
pathview.CanCollide = false
print("run")
if point.Action == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
end
Humanoid.MoveToFinished:Wait()
-- look()
--script.Parent.HumanoidRootPart.Orientation = CFrame.lookAt(thing.Position, thing.Orientation)
end
else
warn("Uh oh, I couldn't calculate a path!")
look() -- function for calculating
end
end
Thanks in advance.