RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"make a script that makes my character walk to a close opposite team player"
local Players = game:GetService("Players") local PathfindingService = game:GetService("PathfindingService") local myPlayer = Players.LocalPlayer local myCharacter = myPlayer.Character local function getNearestOpponent() local nearestPlayer local shortestDistance = math.huge for _, player in ipairs(Players:GetPlayers()) do if player.TeamColor ~= myPlayer.TeamColor then local character = player.Character if character then local distance = (myCharacter.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Magnitude if distance < shortestDistance then shortestDistance = distance nearestPlayer = player end end end end return nearestPlayer end local function moveToOpponent() local opponent = getNearestOpponent() if opponent and opponent.Character then local path = PathfindingService:CreatePath() path:ComputeAsync(myCharacter.HumanoidRootPart.Position, opponent.Character.HumanoidRootPart.Position) for _, waypoint in ipairs(path:GetWaypoints()) do myCharacter.Humanoid:MoveTo(waypoint.Position) myCharacter.Humanoid.MoveToFinished:Wait() end end end moveToOpponent()