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

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

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

2 comments

0

It could be the map if you are using one.

0

?

1 answer

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.

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