Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Pathfinding doesn't work, no console logs nor errors?

Asked by 2 years ago
Edited 2 years ago

So what I'm trying to create here is that the dummy will generate blood parts while walking to the waypoint, after 100 seconds it destroys it, and then after 10 seconds it will bring back the blood parts again, but that's just one of the few things I want the script to do. Here's all of them.

What I'm trying to achieve: 1. Print the time of a waypoint completed by using os.time but I don't know how to end the os time when the humanoid already finished 2. Humanoid will change state to climbing when there's a truss part 3. Print finished and then after a few seconds, It will print that the humanoid is already finished 4. Cframing if not completed on the variable cframe time.

Code:

local pathfindingService = game:GetService("PathfindingService")

local Finished = false

local humanoid = script.Parent.Humanoid
local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso")
local destination = game.Workspace.Destination.Position

local path = pathfindingService:CreatePath()

local root = script.Parent:FindFirstChildWhichIsA("HumanoidRootPart")
local timecframe = 200

path:ComputeAsync(body.Position, destination)

local waypoints = path:GetWaypoints()

for i, v in pairs(waypoints) do
    local waypointpart = Instance.new("Part", workspace)
    waypointpart.Color = BrickColor.new("Really red")
    waypointpart.Size = Vector3.new(math.random(1, 6),math.random(1, 4),math.random(1, 2))
    waypointpart.Transparency = 0.88
    waypointpart.Anchored = true
    waypointpart.CanCollide = true
    wait(100)
    waypointpart:Destroy()
    wait(10)
    waypointpart(workspace)
    end

    for _, waypoint in pairs(waypoints) do
    humanoid:MoveTo(waypoint.Position)
    if waypoint.Action == Enum.PathWaypointAction.Jump then
        humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
    end

    if waypoint.Action == Enum.PathWaypointAction.Climbing then
        humanoid:ChangeState(Enum.HumanoidChangeState.Climbing)
    end
    humanoid.MoveToFinished:Wait()
    destination.Touch:Connect(function(hit)
        local finished = hit and script.Parent.HumanoidRootPart.Position == destination.Position
        if wait(timecframe) and not finished(script.Parent.HumanoidRootPart) then root.CFrame = destination.CFrame
        else
            if finished(script.Parent.HumanoidRooPart) then print('Finished Destination') wait(10) Finished = true
                while Finished == true do
                    task.wait(1)
                    print(script.Parent.Name" Already Finished Waypoint!")
                end
                while Finished == false do
                    task.wait(1)
                    print(os.clock() - os.clock()," "..script.Parent.Name.." is still trying to pathfind waypoint.")
                end
            end
        end
    end)
end

Answer this question