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

Only the players on the East team move with Pathfind? [Answered]

Asked by 6 years ago
Edited 6 years ago

I have two teams, East and West (very creative names). I am using path find to make to make the game more fancy. The script that I'm about to share with you is a server script and when they join, it is injected into the player's character. Only the player on the East Team moves and the West team player's path returns a status of NoPath.

--Services

local PS = game:GetService('PathfindingService')
local W = game:GetService('Workspace')

--Variables

local Rig = script.Parent
wait(1)
local Torso = script.Parent:WaitForChild('Torso')
local Humanoid = script.Parent:WaitForChild('Humanoid')

--Functions

--Find a target
function GetTarget()

    local target = nil
    if Humanoid.Parent.EastTeamCheck.Value == true then
        local Parts = workspace.Goalz:GetDescendants()
        local RandomPart = Parts[math.random(1,#Parts)]
        print(RandomPart.Name)
        RandomPart.Parent = workspace.TakenGoalz
        target = RandomPart.Position
        Rig:MoveTo(workspace.StartGoalz.Position)   

    elseif Humanoid.Parent.EastTeamCheck.Value == false then
        local Parts = workspace.Goals:GetDescendants()
        local RandomPart = Parts[math.random(1,#Parts)]
        print(RandomPart.Name)
        RandomPart.Parent = workspace.TakenGoals
        target = RandomPart.Position
        Rig:MoveTo(workspace.StartGoals.Position)   
    end

    return target;

end

local target = GetTarget()
while wait() do
    if target then
        local path = PS:ComputeRawPathAsync(Torso.Position, target, 500)
        print(path.Status)
        local nodes = path:GetPointCoordinates()
        for i,v in next, nodes do
            Humanoid:MoveTo(v)
            repeat
                distance = (v - Torso.Position).magnitude
                wait()
            until
            distance < 3
        end
    end
end

0
It could be the map if you are using one. H4X0MSYT 536 — 6y
0
? BennyBoiOriginal 293 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

To solve my problem, I got rid of: local path = PS:ComputeRawPathAsync(Torso.Position, target, 500) And I used FindPathAsync which is almost the same except the syntax is

Path FindPathAsync (
    Vector3 start,
    Vector3 finish
)

Hoped this helped some people.

Ad

Answer this question