Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I turn this script into a path with multiple waypoints?

script.Parent.Humanoid.WalkToPoint = Vector3.new(-2238.753, 956.457, -1050.838)

That is the script I have been using. I'm very new to using scripts with NPCs, and just barely managed to make that script. How would I make it into a path with multiple destinations? If I can't, what should I use to make a multi-destination pathfinding script?

1 answer

✓ Accepted answer
local function makeWaypoints(pos1, pos2, amount)
    if typeof(pos1) == "Vector3" and typeof(pos2) == "Vector3" then
        local waypoints = {}
        local pos1 = pos1
        local pos2 = pos2
        local amount = amount or 4
        local magnitude = -((pos1 - pos2).Magnitude) / amount
        local lastCF = CFrame.new(pos1, pos2) * CFrame.new(0, 0, -magnitude)
        for i = 1, amount + 1, 1 do 
            lastCF = CFrame.new(lastCF.Position, pos2) * CFrame.new(0, 0, magnitude)
            table.insert(waypoints, lastCF.Position)
        end
        return waypoints
    end
end

pos1 should be set to the position you want to start from, pos2 should be set to the end position, amount should be set to the amount of waypoints you want.

To get the waypoints loop through the table that makeWaypoints returns.

2 comments

0

Thank you so much!

0

Does it work properly?

This discussion is preserved as it was. New answers, comments, and votes are closed.