Run it
Copy the script and paste it into your executor.
local piggy = script.Parent -- Reference to PiggyBot model
local humanoid = piggy:WaitForChild("Humanoid")
local players = game:GetService("Players")
local targetPlayer = nil -- Variable to store the current target player
function findNearestPlayer()
local nearestPlayer = nil
local nearestDistance = math.huge -- Start with a very high number
for _, player in pairs(players:GetPlayers()) do
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
local distance = (piggy.PrimaryPart.Position - player.Character.HumanoidRootPart.Position).magnitude
if distance < nearestDistance player.Team.Name ~=
nearestDistance = distance
nearestPlayer = player
nearestPlayer
()
targetPlayer = ()
targetPlayer targetPlayer.Character
targetPosition = targetPlayer.Character.HumanoidRootPart.Position
humanoid:(targetPosition)
()
()
Script.