Universal Script πŸ“Œ
1.0k Views
572 Executions

Pathfinding and follow script

Universal Script πŸ“Œ
ScriptDAILY
ScriptDAILYPublished 5
10 months ago
Get an executor
Please login to perform these actions:

Does it work?

No reports yet

No reports yet. Tried it? Be the first to say.

Also noticed:

Description

Pathfind a player. When they are clicked you follow them and they have a red outline only appears for you

View Raw
local PathfindingService = game:GetService("PathfindingService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")

local targetPlayer = nil
local currentHighlight = nil
local path = PathfindingService:CreatePath({
	AgentRadius = 2,
	AgentCanJump = true,
})

-- Function to clean up following state
local function stopFollowing()
	targetPlayer = nil
	if currentHighlight then
		currentHighlight:Destroy()
		currentHighlight = nil
	end
	humanoid:MoveTo(rootPart.Position) -- Stop moving
end

-- Function to follow the target using Pathfinding
local function followTarget()
	while targetPlayer and targetPlayer.Character and targetPlayer.Character:FindFirstChild("HumanoidRootPart") do
		local targetRoot = targetPlayer.Character.HumanoidRootPart
		local destination = targetRoot.Position
		
		-- Only compute path if target is far enough away
		if (rootPart.Position - destination).Magnitude > 5 then
			local success, errorMessage = pcall(function()
				path:ComputeAsync(rootPart.Position, destination)
			end)

			if success and path.Status == Enum.PathStatus.Success then


Comments

0
Log in to join the conversation. Login
No comments yet. Be the first!

Tags

More universal scripts

See all
Script hub
150
987
Bumped 37 minutes ago

Script hub

Lunyx Hub

Script hub
120.8k
221.2k
Bumped 56 minutes ago
Key System
Script hub
10.5k
200.7k
Bumped 1 hour ago

Script hub

KeylessVerified script badgeIRIDIUM HUB | #1

Script hub
33.3k
299.2k
Bumped 4 hours ago
Script hub
23.7k
5.3k
Bumped 4 hours ago
Key System
Paid
High QualityΒ Offering
Universal Script πŸ“Œ
308
978
Bumped 5 hours ago