RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"make a script that loop teleports me to the nearest enemy"
-- server script local Players = game:GetService("Players") local player = Players.LocalPlayer local function teleportToNearestEnemy() while wait(1) do local closestEnemy local closestDistance = math.huge for _, enemy in ipairs(Players:GetPlayers()) do if enemy.TeamColor ~= player.TeamColor then local distance = (player.Character.HumanoidRootPart.Position - enemy.Character.HumanoidRootPart.Position).Magnitude if distance < closestDistance then closestDistance = distance closestEnemy = enemy end end end if closestEnemy then player.Character.HumanoidRootPart.CFrame = closestEnemy.Character.HumanoidRootPart.CFrame + Vector3.new(0, 5, 0) end end end teleportToNearestEnemy() -- This script will teleport the player to the nearest enemy every second. Please note that this script assumes that the player and enemies are on different teams. If there are no teams in your game, you will need to find another way to distinguish between players and enemies.