--!strict local Players = game:GetService("Players") local TweenService = game:GetService("TweenService") -- Configuration constants local VOID_HEIGHT: number = -100 local RESPAWN_OFFSET: Vector3 = Vector3.new(0, 5, 0) local VEHICLE_RESPAWN_CFRAME: CFrame = CFrame.new(0, 10, 0) -- Thread management map to prevent duplicate memory leaks local activeChecks: { [Player]: boolean } = {} local originalPositions: { [Player]: Vector3 } = {} -- Dynamically generates and handles the UI flash on the client screen local function triggerScreenFlash(player: Player) local playerGui = player:FindFirstChildOfClass("PlayerGui") if not playerGui then return end -- 1. Create UI Structural elements local screenGui = Instance.new("ScreenGui") screenGui.Name = "VoidRecoveryGui" screenGui.IgnoreGuiInset = true -- Fills entire display edge-to-edge screenGui.ResetOnSpawn = false local background = Instance.new("Frame") background.Size = UDim2.fromScale(1, 1) background.BackgroundColor3 = Color3.fromRGB(30, 5, 0) -- Ultra-dark warning maroon background.BackgroundTransparency = 1 -- Start transparent for fade-in background.BorderSizePixel = 0 background.Parent = screenGui -- Gradient component for the rich Dark Orange & Red design theme local uigradient = Instance.new("UIGradient") uigradient.Color = ColorSequence.new({ ColorSequenceKeypoint.new(0, Color3.fromRGB(180, 20, 0)), -- Dark Metallic Red ColorSequenceKeypoint.new(1, Color3.fromRGB(220, 80, 0)) -- Intense Dark Orange }) uigradient.Rotation = 45 uigradient.Parent = background -- Centered Warning Alert Text Label local warningText = Instance.new("TextLabel") warningText.Size = UDim2.fromScale(0.8, 0.2) warningText.Position = UDim2.fromScale(0.5, 0.5) warningText.AnchorPoint = Vector2.new(0.5, 0.5) warningText.BackgroundTransparency = 1 warningText.TextColor3 = Color3.fromRGB(255, 220, 200) warningText.Text = "SYSTEM BOUNDARY CRASH DETECTED\n[ RETURNING TO SAFETY ]" warningText.Font = Enum.Font.Code warningText.TextSize = 28 warningText.TextWrapped = true warningText.TextTransparency = 1 warningText.Parent = background screenGui.Parent = playerGui -- 2. Animation Sequences using TweenService local fadeInInfo = TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out) local fadeOutInfo = TweenInfo.new(0.6, Enum.EasingStyle.Quad, Enum.EasingDirection.In) -- Fade In (Snap to screen cover) local tweenBgIn = TweenService:Create(background, fadeInInfo, {BackgroundTransparency = 0.1}) local tweenTextIn = TweenService:Create(warningText, fadeInInfo, {TextTransparency = 0}) tweenBgIn:Play() tweenTextIn:Play() tweenBgIn.Completed:Wait() -- Hold physics until screen is fully covered task.wait(0.6) -- Brief visual suspension hold -- Fade Out (Dissolve effect back to game action) local tweenBgOut = TweenService:Create(background, fadeOutInfo, {BackgroundTransparency = 1}) local tweenTextOut = TweenService:Create(warningText, fadeOutInfo, {TextTransparency = 1}) tweenBgOut:Play() tweenTextOut:Play() tweenBgOut.Completed:Wait() -- Complete memory cleanup screenGui:Destroy() end -- Safely teleports the player and vehicle out of the void boundary local function handleVoidTransition(player: Player, vehicleModel: Model, spawnPoint: Vector3) local character = player.Character if not character then return end local rootPart = character:FindFirstChild("HumanoidRootPart") :: BasePart? local vehicleRoot = vehicleModel.PrimaryPart or vehicleModel:FindFirstChildWhichIsA("BasePart") :: BasePart? local humanoid = character:FindFirstChildOfClass("Humanoid") -- Fire UI screen transition overlay on a separate parallel thread task.spawn(triggerScreenFlash, player) task.wait(0.2) -- Synchronized pause to let UI completely shield the frame transition -- 1. Unseat the player safely if humanoid then humanoid.Sit = false end -- Allow the physics engine to safely unbind the seat weld task.wait(0.1) -- 2. Teleport player and zero out forces if rootPart and rootPart:IsDescendantOf(workspace) then rootPart.AssemblyLinearVelocity = Vector3.zero rootPart.AssemblyAngularVelocity = Vector3.zero rootPart.CFrame = CFrame.new(spawnPoint + RESPAWN_OFFSET) end -- 3. Teleport or clean up vehicle asset if vehicleRoot and vehicleRoot:IsDescendantOf(workspace) then vehicleRoot.AssemblyLinearVelocity = Vector3.zero vehicleRoot.AssemblyAngularVelocity = Vector3.zero vehicleModel:PivotTo(VEHICLE_RESPAWN_CFRAME) end end -- Tracks vehicle depth profile via server performance polling local function startBoundaryCheck(player: Player, vehicleModel: Model, vehicleSeat: VehicleSeat) if activeChecks[player] then return end activeChecks[player] = true local vehicleRoot = vehicleModel.PrimaryPart or vehicleModel:FindFirstChildWhichIsA("BasePart") :: BasePart? if not vehicleRoot then activeChecks[player] = nil return end local character = player.Character if character and character:FindFirstChild("HumanoidRootPart") then originalPositions[player] = (character.HumanoidRootPart :: BasePart).Position else originalPositions[player] = Vector3.new(0, 10, 0) end task.spawn(function() while vehicleModel and vehicleModel.Parent and vehicleSeat.Occupant do if vehicleRoot and vehicleRoot.Position.Y < VOID_HEIGHT then local fallbackLocation = originalPositions[player] or Vector3.new(0, 10, 0) handleVoidTransition(player, vehicleModel, fallbackLocation) break end task.wait(0.5) end originalPositions[player] = nil activeChecks[player] = nil end) end -- Hook initialization logic onto parent seat object local vehicleSeat = script.Parent :: VehicleSeat if vehicleSeat:IsA("VehicleSeat") then vehicleSeat:GetPropertyChangedSignal("Occupant"):Connect(function() local humanoid = vehicleSeat.Occupant if humanoid then local character = humanoid.Parent if not character then return end local player = Players:GetPlayerFromCharacter(character) local vehicleModel = vehicleSeat:FindFirstAncestorOfClass("Model") if player and vehicleModel then startBoundaryCheck(player, vehicleModel, vehicleSeat) end end end) end