How to make a part teleport randomly off screen?

im creating slender ai, and i need to know how to make part teleport randomly off screen

i tried it but it teleports only behind player, not off screen

can someone help?

You can probably just teleport it somewhere undergound (or underground relative to the player).

If it’s a part:

Part.CFrame = CFrame.new(0,-100,0)

If it’s a model:

Model:PivotTo(CFrame.new(0,-100,0))

no i mean everywhere you dont see, not underground

its slender he should teleport when you dont see him and he need to teleport everywhere you dont see (on some distance)

Could you please send us your current code?

You can use this function:

local Camera = workspace.CurrentCamera

function GetPartsInView()
   local parts = {}
   for i, obj in pairs(workspace:GetDescendants()) do
      local vector, isOnScreen = Camera:WorldToScreenPoint(obj.Position)
      if isOnScreen then
         table.insert(parts, obj)
      end
   end

   return parts
end

local partsinview = GetPartsInView()

(How to retrieve a table of every object within view of camera - #5 by TenBlocke)
then, check if any of the parts in view are apart of the slender and decide whether or not to teleport.

local TS = game:GetService("TweenService")

local part = workspace:WaitForChild("Slender")
local player = game.Players.LocalPlayer
local character = player.Character
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")

local camera = workspace.CurrentCamera
local static = player.PlayerGui:WaitForChild("Static").ImageLabel

local slenderspeed = workspace.SlenderValues.SlenderSpeed

local slenderisvisible = workspace:WaitForChild("SlenderValues").SlenderIsVisible

local distance = game.Workspace.SlenderValues.Distance
local TeleportTime = game.Workspace.SlenderValues.TeleportTime


local function teleportslender()
	local playerPosition = character.HumanoidRootPart.Position
	local playerDirection = character.HumanoidRootPart.CFrame.LookVector
	local distanceBehind = -distance.Value
	local randomOffset = Vector3.new(math.random(-distance.Value, distance.Value), 1, math.random(-distance.Value, distance.Value))  -- Random offset

	local newPosition = playerPosition + (playerDirection * distanceBehind) + randomOffset

	part.Position = newPosition
end

while task.wait(TeleportTime.Value) do
	local a,see = workspace.CurrentCamera:WorldToScreenPoint(part.CFrame.Position)
	part.CFrame = CFrame.lookAt(part.Position, camera.CFrame.Position)
	
	part.Velocity = (camera.CFrame.Position - part.Position).Unit*slenderspeed.Value
	if slenderisvisible.Value == false and see then
	print("slender is teleporting")
	teleportslender()
	elseif slenderisvisible.Value == true and not see then
	part.Position = part.Position
	end
end

this is current slender ai [made with tears]

Then do you want it to teleport somewhere near the player, but outside their screen?

yes, also i want to change the max and min distance between player and slender