Kernel Script feedback

Hello i just wanna hear feedback about my Kernel that Emulates/Simulates hardware stress & usage

Krnl.lua

--// Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("ScreenGui")
local systemManagerWindow = screenGui:WaitForChild("SystemManagerWindow")
local performanceTab = systemManagerWindow:WaitForChild("PerformanceTab")
local menu = screenGui:WaitForChild("Menu")
local bios = screenGui:WaitForChild("BIOS")
local settingsWindow = screenGui:FindFirstChild("SettingsWindow") -- Assuming SettingsWindow exists

-- Crash Frame
local crashFrame = screenGui:FindFirstChild("Crash3")
local kernelDumpLabel = crashFrame and crashFrame:FindFirstChild("KernelDump")
local kernelPanicked = false

--// UI Elements
local cpuLabel = performanceTab:WaitForChild("CPULabel")
local memoryLabel = performanceTab:WaitForChild("MemoryLabel")
local gpuLabel = performanceTab:WaitForChild("GPULabel")
local cpuFreqLabel = performanceTab:WaitForChild("CPUFreqLabel")
local cpuTempLabel = performanceTab:WaitForChild("CPUTempLabel")
local storageLabel = performanceTab:WaitForChild("StorageLabel")
local networkLabel = performanceTab:WaitForChild("NetworkLabel")

local cpuBar = performanceTab:WaitForChild("CPUBar")
local gpuBar = performanceTab:WaitForChild("GPUBar")
local memoryBar = performanceTab:WaitForChild("MemoryBar")
local storageBar = performanceTab:WaitForChild("StorageBar")
local networkBar = performanceTab:WaitForChild("NetworkBar")

local cpuTextBox = menu:WaitForChild("CPUFreqTextBox")
local applyButton = menu:WaitForChild("ApplyButton")

-- Reference to the drive button inside FileExplorer
local fileExplorerWindow = screenGui:FindFirstChild("FileExplorerWindow")
local driveTextButton = nil

if fileExplorerWindow then
	local drives = fileExplorerWindow:FindFirstChild("Drives")
	if drives then
		local driveButton = drives:FindFirstChild("ImageButton")
		if driveButton and driveButton:IsA("ImageButton") then
			driveTextButton = driveButton:FindFirstChildOfClass("TextButton")
		end
	end
end

-- SettingsWindow UI for Disk
local diskMenu = settingsWindow and settingsWindow:FindFirstChild("Frame") and settingsWindow.Frame:FindFirstChild("DiskMenu")
local diskBarBg = diskMenu and diskMenu:FindFirstChild("DiskBarBg")
local diskBar = diskBarBg and diskBarBg:FindFirstChild("Bar")
local diskAmount = diskBarBg and diskBarBg:FindFirstChild("DiskAmount")

-- UI elements (place near other UI element definitions)
local systemUsageLabel = diskMenu and diskMenu:FindFirstChild("SystemUsage")
local userUsageLabel = diskMenu and diskMenu:FindFirstChild("UserUsage")
local cacheUsageLabel = diskMenu and diskMenu:FindFirstChild("CacheUsage")
local clearCacheButton = diskMenu and diskMenu:FindFirstChild("ClearCacheButton")

-- Warning Windows
local warningWindow = screenGui:FindFirstChild("LOW_DISK_ERRWarningWindow-")
local lowRamWarningWindow = screenGui:FindFirstChild("LOW_RAM_ERRWarningWindow-")
local appFailWarningWindow = screenGui:FindFirstChild("APP_FAILWarningWindow-")

--// Remotes
local cpuFrequencyRemote = ReplicatedStorage:WaitForChild("CPUFrequencyRemote")
local cpuFrequencyUpdateRemote = ReplicatedStorage:WaitForChild("CPUFrequencyUpdateRemote")

--// Kernel Settings
local frequency = 2.4
local maxRAM = 8192 -- total RAM in MB
local maxStorageGB = 512
local lowDiskThreshold = maxStorageGB * 1024 * 0.95 -- 95% of total disk in MB
local kernelVer = "Krnl_Ver = Pinux/Linux ver2.3 122925/1028PM"
local ramvendor = "Zyrex Technologies"
local ramtype = "DDR5 - 3500Mhz"
local mobovendor = "AGUS"
local mobotype = "E1504FA"
local cpuvendor =  "ZMD"
local cputype = "Zuren 3 7320U"
local gpuvendor = "ZMD"
local gputype = "Xadeon Video"
local drivevendor = "BruhGroup"
local drivetype = "GROUPFGPUUHDD512"
local netvendor = "Unstabletek"
local nettype = "MT7902 - 2400Mbps - 2.4/5/6Ghz"
local battvendor = "OEM"
local batttype = "4500mAh - Li-ion - OEMAGUS4500"
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local GPU_SMOOTHING = 0.08      -- smoothing factor (lower = smoother)
local MAX_GPU_DELTA = 3          -- max change per second
local DEFAULT_GPU_COST = 5       -- default GPU cost per window
local IDLE_LOAD = 6              -- baseline GPU load
local TEMP_THROTTLE = 85         -- temperature threshold
local THROTTLE_FACTOR = 0.75     -- how much GPU drops when throttled
local GPUVram = 512 -- in MB
local usedVRAM = 0
local CPUThreads = 8
local CPUCores = 4 
local IsLagging = false
-- Remove BindableEvent logic entirely

-- Local variable to store gallery storage
local galleryStorageMB = 0

-- Listen for changes to the attribute "GalleryStorageUsage"
player:GetAttributeChangedSignal("GalleryStorageUsage"):Connect(function()
	local newVal = tonumber(player:GetAttribute("GalleryStorageUsage"))
	if newVal then
		galleryStorageMB = newVal
	end
end)

--lag
-- Initialize lagging attribute
player:SetAttribute("IsLagging", false)

-- Also initialize it immediately on load (in case attribute is already set)
local initialGalleryUsage = tonumber(player:GetAttribute("GalleryStorageUsage"))
if initialGalleryUsage then
	galleryStorageMB = initialGalleryUsage
end

--// Process Manager
local processFolder = ReplicatedStorage:FindFirstChild("ProcessFolder") or Instance.new("Folder")
processFolder.Name = "ProcessFolder"
processFolder.Parent = player.PlayerGui

-- CPU scheduling model
local cpuScheduler = {
	cores = CPUCores,
	threads = CPUThreads,
	coreLoad = {}, -- per-core usage %
}

-- initialize cores
for i = 1, cpuScheduler.cores do
	cpuScheduler.coreLoad[i] = 0
end

--// Tracked Windows
--// Automatically find and track windows
--// Automatically find and track windows
local trackedWindows = {}

local function updateWindowTracking()
	local currentWindows = {}

	-- Scan ScreenGui for windows
	for _, child in pairs(screenGui:GetChildren()) do
		if child:IsA("Frame") and (child.Name:match("Window") or child.Name:match("App")) then
			currentWindows[child.Name] = child
		end
	end

	-- Add new windows to tracking
	for name, window in pairs(currentWindows) do
		if not trackedWindows[name] then
			trackedWindows[name] = window

			local isNonApp = window:FindFirstChild("IsNonAppWindow")
			if not (isNonApp and isNonApp.Value == true) then
				-- Create a process only if NOT marked non-app
				local processValue = Instance.new("StringValue")
				processValue.Name = name
				processValue.Value = "Initializing..."
				processValue.Parent = processFolder
			end
		end
	end

	-- Remove old entries
	for name, window in pairs(trackedWindows) do
		if not currentWindows[name] then
			trackedWindows[name] = nil

			local existing = processFolder:FindFirstChild(name)
			if existing then
				existing:Destroy()
			end
		end
	end
end

--// Heavy resource usage lookup tables still work fine
-- Improved GPU cost system
local gpuCost = {
	BrowserWindow = 18,
	PaintWindow = 12,
	MusicPlayerWindow = 8,
	PictureViewerWindow = 9,
	VideoViewerWindow = 15,
	ThePowderToyWindow = 25,
	ProgressBar98Window = 10,
	ArtmaxxWindow = 20,
	CubeTownWindow = 30,
	PingpongWindow = 15,
	ZombersWindow = 24,
	SlidemaxxWindow = 29,
}

local DEFAULT_GPU_COST = 6
local smoothedGPU = 15       -- Starting GPU load
local GPU_SMOOTHING = 0.05   -- 0.0 = instant, 1.0 = frozen

local gpuVramCost = {
	BrowserWindow = 96,
	VideoViewerWindow = 128,
	PictureViewerWindow = 64,
	PaintWindow = 48,
	ThePowderToyWindow = 160,
	ArtmaxxWindow = 192,
	CubeTownWindow = 256,
	ZombersWindow = 224,
	PingpongWindow = 96,
}

local DEFAULT_VRAM_COST = 32

local cpuThreadCost = {
	BrowserWindow = 2,
	ThePowderToyWindow = 3,
	CubeTownWindow = 3,
	ZombersWindow = 2,
	ArtmaxxWindow = 2,
	VideoViewerWindow = 2,
}

local DEFAULT_THREAD_COST = 1

local gpuHeavyWindows = {
	["BrowserWindow"] = true,
	["PaintWindow"] = true,
	["MusicPlayerWindow"] = true,
	["ThePowderToyWindow"] = true,
	["ProgressBar98Window"] = true,
	["ArtmaxxWindow"] = true,
	["CubeTownWindow"] = true,
	["PingpongWindow"] = true,
	["ZombersWindow"] = true,
}

local memoryHeavyWindows = {
	["BrowserWindow"] = true,
	["NotepadWindow"] = true,
	["FileExplorerWindow"] = true,
	["SettingsWindow"] = true,
}

local networkHeavyWindows = {
	["BrowserWindow"] = true,
	["ChatWindow"] = true,
	["DarkBrowserWindow"] = true,
	["NetworkManagerWindow"] = true,
	["AppInstallWindow"] = true,
	["EchoWindow"] = true,
}

local storageHeavyWindows = {
	["FileExplorerWindow"] = true,
	["NotepadWindow"] = true,
	["PaintWindow"] = true,
	["AppInstallWindow"] = true,
}

local cacheHeavyWindows = {
	["BrowserWindow"] = true,
	["PaintWindow"] = true,
	["CodemaxxWindow"] = true,
	["AppInstallWindow"] = true,
}

-- Add this after your window tracking
for name, window in pairs(trackedWindows) do
	-- Create a connection for each window's visibility change
	if not window.VisibilityChangedConnection then
		window.VisibilityChangedConnection = window:GetPropertyChangedSignal("Visible"):Connect(function()
			-- This will be updated in the main loop anyway, so we just need to ensure the connection exists
		end)
	end
end

--// Desktop Icons and Cache Handling
local desktopFrame = screenGui:WaitForChild("DesktopFrame")
local desktopIconsFrame = desktopFrame:WaitForChild("Frame")

-- Cache management variables
local cacheMB = 0

-- Keep track of which icons were hidden due to warning
local hiddenIcons = {}

-- Simulate storage components
local function getSystemStorage()
	return math.random(5, 10) * 1024 -- System takes 5-10 GB, convert to MB
end

local function getUserCreatedStorage()
	-- Count visible ImageButtons as before
	local count = 0
	for _, child in pairs(desktopIconsFrame:GetChildren()) do
		if child:IsA("ImageButton") and child.Visible then
			count += 1
		end
	end

	local desktopStorage = count * 2048 -- MB
	return desktopStorage + galleryStorageMB
end

local function getCacheStorage()
	return cacheMB
end

local function updateCache()
	local activeMB = 0
	for name, window in pairs(trackedWindows) do
		if window.Visible then
			if cacheHeavyWindows[name] then
				activeMB += 500
			else
				activeMB += 50
			end
		end
	end

	-- Slowly decay cache if no new usage
	if activeMB < cacheMB then
		cacheMB = math.max(cacheMB - 1, activeMB)
	else
		cacheMB = activeMB
	end
end

--// RAM Simulation Constants
local RAM_USAGE_HEAVY_MIN = 500
local RAM_USAGE_HEAVY_MAX = 1024
local RAM_USAGE_LIGHT_MIN = 256
local RAM_USAGE_LIGHT_MAX = 500
local RAM_WARNING_THRESHOLD = 0.99 * maxRAM

-- Simulate RAM usage based on visible windows
local function calculateRAMUsage()
	local usage = 0

	for name, window in pairs(trackedWindows) do
		if window.Visible then
			local heavy = memoryHeavyWindows[name]
			usage += heavy and math.random(RAM_USAGE_HEAVY_MIN, RAM_USAGE_HEAVY_MAX) or math.random(RAM_USAGE_LIGHT_MIN, RAM_USAGE_LIGHT_MAX)
		end
	end

	return math.clamp(usage, 0, maxRAM)
end

-- Check if RAM is critically full
local function isRAMFull()
	return calculateRAMUsage() >= RAM_WARNING_THRESHOLD
end

-- Clamp function
--function mathclamp(val, lower, upper)
--	if val < lower then return lower end
--	if val > upper then return upper end
--	return val
--end

--cpu mechanic
local function calculateCPUUsage()

	-- reset core loads
	for i = 1, cpuScheduler.cores do
		cpuScheduler.coreLoad[i] = 0
	end

	local usedThreads = 0
	local activeWindows = 0

	for name, window in pairs(trackedWindows) do
		if window.Visible then
			activeWindows += 1
			usedThreads += cpuThreadCost[name] or DEFAULT_THREAD_COST
		end
	end

	-- Thread saturation factor
	local threadPressure = usedThreads / cpuScheduler.threads
	threadPressure = math.clamp(threadPressure, 0, 2)

	-- Distribute load across cores
	for i = 1, cpuScheduler.cores do
		cpuScheduler.coreLoad[i] =
			math.clamp((threadPressure * 100) / cpuScheduler.cores, 0, 100)
	end

	-- Average core load = total CPU usage
	local total = 0
	for i = 1, cpuScheduler.cores do
		total += cpuScheduler.coreLoad[i]
	end

	local avgCPU = total / cpuScheduler.cores

	-- Frequency scaling
	avgCPU *= math.clamp(frequency / 2.4, 0.6, 1.5)

	-- Idle floor
	if activeWindows == 0 then
		avgCPU = 2
	end

	return math.clamp(avgCPU, 0, 100), usedThreads
end

local function calculateVRAMUsage()
	local total = 0

	for name, window in pairs(trackedWindows) do
		if window.Visible then
			total += gpuVramCost[name] or DEFAULT_VRAM_COST
		end
	end

	return math.clamp(total, 0, GPUVram * 2) -- allow oversubscription
end

--gpu mechanic
function calculateGPUUsage(frequency, cpuTemp)

	local vramPressure = usedVRAM / GPUVram

	-- 1. Calculate raw GPU cost based on visible windows
	local totalCost = 0
	for name, window in pairs(trackedWindows) do
		if window.Visible then
			totalCost = totalCost + (gpuCost[name] or DEFAULT_GPU_COST)
		end
	end

	-- 2. Frequency scaling (normalized)
	local freqScale = math.clamp(frequency / 2.4, 0.5, 2)

	-- 3. Raw GPU usage with idle load
	local rawGPU = math.clamp(totalCost * freqScale + IDLE_LOAD, 0, 100)

	-- 4. Thermal throttling
	if cpuTemp >= TEMP_THROTTLE then
		rawGPU = rawGPU * THROTTLE_FACTOR
	end

	--5
	-- VRAM pressure penalty
	if vramPressure > 1 then
		rawGPU = rawGPU * math.clamp(1.2 - (vramPressure - 1), 0.4, 1)
	end

	-- 5. Limit how fast GPU can change per update
	local delta = rawGPU - smoothedGPU
	delta = math.clamp(delta, -MAX_GPU_DELTA, MAX_GPU_DELTA)
	smoothedGPU = smoothedGPU + delta

	return smoothedGPU
end

--// Helpers
local function setFrequency(newFreq)
	if typeof(newFreq) == "number" and newFreq > 0 then
		frequency = newFreq
		cpuFreqLabel.Text = ("CPU Frequency: %.2f GHz"):format(frequency)
		if menu:FindFirstChild("Main") then
			local cpuFreqPreviewLabelMenu = menu.Main:FindFirstChild("CPUFreqPreviewLabel")
			if cpuFreqPreviewLabelMenu then
				cpuFreqPreviewLabelMenu.Text = ("%d MHz"):format(frequency * 1000)
			end
		end
		if bios:FindFirstChild("CPUFreqPreviewLabel") then
			bios.CPUFreqPreviewLabel.Text = ("%d MHz"):format(frequency * 1000)
		end
	end
end

local function adjustUsage(value, lowFactor, highFactor)
	if frequency < 1 then
		return value * lowFactor
	else
		return value * (frequency / 2.4)
	end
end

local function getActiveWindowCount()
	local count = 0
	for _, window in pairs(trackedWindows) do
		if window.Visible then
			count += 1
		end
	end
	return count
end

local function countVisibleWindows(filterTable)
	local count = 0
	for name, window in pairs(trackedWindows) do
		if window.Visible and filterTable[name] then
			count += 1
		end
	end
	return count
end

local function countVisibleStorageHeavy()
	local count = 0
	for name, window in pairs(trackedWindows) do
		if window.Visible and storageHeavyWindows[name] then
			count += 1
		end
	end
	return count
end

local function countNetworkLoad()
	local isConnected = player:GetAttribute("WifiConnected")
	local speedMbps = player:GetAttribute("WifiSpeed") or 0

	if not isConnected or speedMbps <= 0 then
		return 0
	end

	-- Count how many network-heavy apps are open
	local activeWindows = 0
	for name, window in pairs(trackedWindows) do
		if window.Visible and networkHeavyWindows[name] then
			activeWindows += 1
		end
	end

	if activeWindows == 0 then
		return 0
	end

	-- Simulate each app using 2–5 Mbps
	local simulatedUsageMbps = 0
	for i = 1, activeWindows do
		simulatedUsageMbps += math.random(2, 5)
	end

	-- Convert usage to a percentage of player’s wifi speed
	local percentUsage = (simulatedUsageMbps / speedMbps) * 100
	return math.clamp(math.floor(percentUsage), 0, 100)
end

local function simulateStats(usedThreads)
	local totalVisible = getActiveWindowCount()

	-- CPU is still simulated normally
	local baseCPU = math.clamp(totalVisible * 5, 5, 90)
	local cpu = adjustUsage(baseCPU, 0.5, 1.25)

	-- REMOVE OLD GPU LOGIC COMPLETELY:
	-- (We now return GPU = 0 because main loop uses calculateGPUUsage())
	-- local gpuVisible = countVisibleWindows(gpuHeavyWindows)
	-- local baseGPU = math.clamp(gpuVisible * 8 + math.random(10, 30), 10, 100)
	-- local gpu = adjustUsage(baseGPU, 0.8, 1.15)

	-- Use RAM system
	local mem = calculateRAMUsage()

	-- Temperature stays the same
	local temp = math.floor(
		35 +
			(cpu / 100) * 40 +
			(usedThreads / CPUThreads) * 20 +
			math.random(-3, 3)

	)

	-- Update cache based on active windows
	updateCache()

	-- Storage calculation
	local usedStorageMB =
		getSystemStorage() +
		getUserCreatedStorage() +
		getCacheStorage()

	usedStorageMB = math.clamp(usedStorageMB, 0, maxStorageGB * 1024)

	-- Network load calculation
	local networkUsage = countNetworkLoad()

	-- GPU is NOT returned from here anymore
	-- because GPU is handled by calculateGPUUsage()
	return cpu, 0, mem, temp, usedStorageMB, networkUsage
end

local function formatStorageAmount(mb)
	if mb >= 1024 then
		return ("%.1f GB"):format(mb / 1024)
	else
		return ("%d MB"):format(mb)
	end
end

local function tryOpenWindow(window)
	if window and window.Visible then
		return true
	end
	return false
end

local function setWindowVisible(window, visible)
	if window then
		window.Visible = visible
	end
end

local function hideRandomDesktopIcons(count)
	local visibleIcons = {}
	for _, icon in ipairs(desktopIconsFrame:GetChildren()) do
		if icon:IsA("ImageButton") and icon.Visible then
			table.insert(visibleIcons, icon)
		end
	end

	-- Shuffle and hide a few
	for i = 1, math.min(count, #visibleIcons) do
		local randomIndex = math.random(1, #visibleIcons)
		local iconToHide = visibleIcons[randomIndex]
		iconToHide.Visible = false
		table.remove(visibleIcons, randomIndex)
	end
end

-- When RAM is full and an app window opens, hide it and show APP_FAILWarningWindow-
-- Handle RAM-based app launch restrictions
local function handleAppLaunch(name, window)
	if not window or not window:IsA("Frame") then return end

	if isRAMFull() then
		setWindowVisible(window, false)

		if appFailWarningWindow then
			appFailWarningWindow.Visible = true
		end
	else
		if appFailWarningWindow then
			appFailWarningWindow.Visible = false
		end
	end
end

-- Connect window visibility changes to check RAM usage
for name, window in pairs(trackedWindows) do
	window:GetPropertyChangedSignal("Visible"):Connect(function()
		if window.Visible then
			handleAppLaunch(name, window)
		end
	end)
end

-- Utility: Generate a random session ID in hex (e.g., 0x1A2B3C4D)
local function generateSessionId()
	local part1 = math.random(0, 0xFFFF)
	local part2 = math.random(0, 0xFFFF)
	return string.format("0x%04X%04X", part1, part2)
end

-- Kernel panic Stop codes
local PanicHexCodes = {
	CPU_OVERHEAT     = { code = "0x0000A001", name = "CPU_OVERHEAT" },
	OUT_OF_MEMORY    = { code = "0x0000B00F", name = "OUT_OF_MEMORY" },
	STORAGE_FULL     = { code = "0x0000C0FF", name = "STORAGE_FULL" },
	INVALID_FREQ     = { code = "0x0000A002", name = "INVALID_CPU_FREQ" },
	CACHE_LEAK       = { code = "0x0000B0C3", name = "CACHE_LEAK" },
	MISSING_FILES    = { code = "0x0000D404", name = "MISSING_FILES" },
	TOO_MANY_WINDOWS = { code = "0x0000D0F0", name = "TOO_MANY_WINDOWS" },
	VRAM_OVERFLOW = { code = "0x0000E0VR", name = "GPU_VRAM_OVERFLOW" },
	DRIVER_FAILURE   = { code = "0x0000E001", name = "DRIVER_FAILURE" },
	UNKNOWN          = { code = "0xFFFFFFFF", name = "UNKNOWN_ERROR" },
}

--Kernel Panic Function
local function triggerKernelPanic(reason, hexData)
	if kernelPanicked or not crashFrame or not kernelDumpLabel then return end
	kernelPanicked = true

	-- 🛠️ Capture RAM usage BEFORE hiding windows
	local ramBeforePanic = calculateRAMUsage()

	-- Capture before hiding windows
	local activeWindowsBeforePanic = getActiveWindowCount()

	for _, window in pairs(trackedWindows) do
		window.Visible = false
	end


	crashFrame.Visible = true

	local code = hexData and hexData.code or "0xFFFFFFFF"
	local label = hexData and hexData.name or "UNKNOWN_ERROR"
	local time = os.date("%H:%M:%S")
	local sessionId = generateSessionId()
	local address = string.format("0x%04X:0x%04X", math.random(0, 0xFFFF), math.random(0, 0xFFFF))

	local dump = "[KERNEL PANIC] SYSTEM HALTED\n"
	dump ..= "STOP CODE: " .. code .. " — " .. label .. "\n"
	dump ..= "Trace: kernel.monitorForPanics() → panic.trigger()\n"
	dump ..= "Reason: " .. (reason or "Unknown critical failure") .. "\n"
	dump ..= "Error Address: " .. address .. "\n"
	dump ..= "Time: " .. time .. " | Session ID: " .. sessionId .. "\n"
	dump ..= "---------------------------\n"
	dump ..= "CPU Frequency: " .. tostring(frequency) .. " GHz\n"
	dump ..= "RAM Usage: " .. tostring(ramBeforePanic) .. " MB\n"
	dump ..= "Storage: " .. tostring(getUserCreatedStorage() + getSystemStorage()) .. " MB\n"
	dump ..= "Active Windows: " .. tostring(activeWindowsBeforePanic) .. "\n"
	dump ..= "---------------------------\n"
	dump ..= "Please recover change-inflicting settings or reboot your system.\n"
	dump ..= kernelVer

	kernelDumpLabel.Text = dump
end

-- Monitor for auto panic conditions
local function monitorForPanics(cpu, gpu, mem, temp, usedStorageMB, networkUsage)
	if kernelPanicked then return end

	if temp >= 105 then
		triggerKernelPanic("Critical CPU Overheat Detected: " .. temp .. "°C", PanicHexCodes.CPU_OVERHEAT)
	elseif calculateRAMUsage() > RAM_WARNING_THRESHOLD then
		triggerKernelPanic("Out of Memory: RAM usage exceeded limits.", PanicHexCodes.OUT_OF_MEMORY)
	elseif usedStorageMB >= maxStorageGB * 1024 then
		triggerKernelPanic("Disk Overflow: Storage exceeded capacity.", PanicHexCodes.STORAGE_FULL)
	elseif frequency > 5 or frequency < 0.5 then
		triggerKernelPanic("Invalid CPU Frequency: " .. frequency .. " GHz", PanicHexCodes.INVALID_FREQ)
	elseif cacheMB > 2900 then
		triggerKernelPanic("Cache Memory Leak Detected: " .. cacheMB .. " MB", PanicHexCodes.CACHE_LEAK)
	elseif usedVRAM > GPUVram * 1.5 then
		triggerKernelPanic(
			"GPU VRAM Exhausted: " .. usedVRAM .. "MB / " .. GPUVram .. "MB",
			PanicHexCodes.VRAM_OVERFLOW
		)
	end
end

local function validateSystemIntegrity()
	local missingComponents = {}

	-- Check for DesktopFrame
	if not screenGui:FindFirstChild("DesktopFrame") then
		triggerKernelPanic("Critical system component 'DesktopShellFileBrwsr.Shell' is missing.", PanicHexCodes.MISSING_FILES)
		return -- Stop further checking if this core element is missing
	end

	if not playerGui:FindFirstChild("DexConfig") then
		triggerKernelPanic("Critical system component 'DEXantitamper.Dll' is missing.", PanicHexCodes.MISSING_FILES)
		return -- Stop further checking if this core element is missing
	end

	if not playerGui:FindFirstChild("CrashConfig") then
		triggerKernelPanic("Critical system component 'crshcfg.cfg' is missing.", PanicHexCodes.MISSING_FILES)
		return -- Stop further checking if this core element is missing
	end

	if not playerGui:FindFirstChild("Krnl") then
		triggerKernelPanic("Critical system com@$43%Ffs hsgh&#&89*#&*87783&&3h STOP**** AT 0x334FFe1 RAM ADDRESS 0xq80FF1 ", PanicHexCodes.MISSING_FILES)
		return -- Stop further checking if this core element is missing
	end

	-- Check for NightLightOverlay and BrightnessOverlay in PlayerGui > ScreenGui
	local nightLight = screenGui:FindFirstChild("NightLightOverlay")
	local brightnessOverlay = screenGui:FindFirstChild("BrightnessOverlay")

	if not nightLight or not brightnessOverlay then
		triggerKernelPanic("Display driver components missing: " ..
			(tostring(nightLight) == "nil" and "posgrphlib - nightlightfeaturectrlmdl " or "") ..
			(tostring(brightnessOverlay) == "nil" and "posgrphlib - brightnessctrlmdl" or ""),
			PanicHexCodes.DRIVER_FAILURE)
		return
	end
end

-- Main update loop
-- Main update loop (again)
-- Main Update loop but written by an furry
-- Main update loop but can lag
local systemIntegrityCounter = 0
task.spawn(function()
	while true do
		-- Always simulate stats (you might want to gate this too if you freeze simulation on panic)
		local cpu, usedThreads = calculateCPUUsage()
		local _, _, mem, temp, usedStorageMB, networkUsage = simulateStats(usedThreads)
		usedVRAM = calculateVRAMUsage()
		local gpu = calculateGPUUsage(frequency, temp)
		local ramUsage = calculateRAMUsage()

		-- Update process folder for other scripts - CORRECTED VERSION
		-- First, clean up any processes that don't correspond to actual windows
		for _, processValue in pairs(processFolder:GetChildren()) do
			if processValue:IsA("StringValue") then
				local windowExists = trackedWindows[processValue.Name] ~= nil
				if not windowExists then
					-- Remove processes for windows that no longer exist
					processValue:Destroy()
				end
			end
		end

		-- Now update all existing processes and create new ones for new windows
		for name, window in pairs(trackedWindows) do
			local processValue = processFolder:FindFirstChild(name)

			-- Check if window still exists and is valid
			local windowExists = window and window.Parent and window:IsDescendantOf(game)
			local isVisible = window and window.Visible or false

			if processValue then
				-- Update existing process
				if windowExists and isVisible then
					-- Window is active and visible
					local cpuUsage = math.random(2, 15)
					local ramUsage = math.random(100, 600)
					local state = "Running"

					processValue.Value = string.format(
						"%s|State=%s|CPU=%d%%|RAM=%dMB",
						name, state, cpuUsage, ramUsage
					)
				else
					-- Window is hidden, destroyed, or parented elsewhere
					processValue.Value = string.format(
						"%s|State=Suspended|CPU=0%%|RAM=0MB",
						name
					)
				end
			else
				-- Check IsNonAppWindow before creating processes
				local isNonApp = window:FindFirstChild("IsNonAppWindow")
				if not (isNonApp and isNonApp.Value == true) then
					local newProcess = Instance.new("StringValue")
					newProcess.Name = name
					newProcess.Value = string.format(
						"%s|State=%s|CPU=%d%%|RAM=%dMB",
						name,
						isVisible and "Running" or "Suspended",
						isVisible and math.random(2, 15) or 0,
						isVisible and math.random(100, 600) or 0
					)
					newProcess.Parent = processFolder
				end
			end
		end
		
		-- Determine if the system is "lagging"
		local laggingThresholdCPU = 45       -- CPU usage % above which we consider lagging
		local laggingThresholdRAM = 0.9 * maxRAM -- RAM usage above 90% of max
		local laggingThresholdGPU = 49       -- GPU usage %

		IsLagging = (cpu >= laggingThresholdCPU) or (ramUsage >= laggingThresholdRAM) or (gpu >= laggingThresholdGPU)

		-- Update the attribute
		player:SetAttribute("IsLagging", IsLagging)

		-- Always update attributes (even in panic)
		local status = kernelPanicked and "PANIC" or "OK"
		player:SetAttribute("PanicStatus", status)
		player:SetAttribute("CPUStats", tostring(math.floor(cpu)))
		player:SetAttribute("GPUStats", tostring(math.floor(gpu)))
		player:SetAttribute("RAMStats", tostring(math.floor(ramUsage / maxRAM * 100)))
		player:SetAttribute("STRStats", tostring(math.floor(usedStorageMB / (maxStorageGB * 1024) * 100)))
		player:SetAttribute("NETStats", tostring(networkUsage))
		player:SetAttribute("KernelVer", kernelVer)
		player:SetAttribute("RamVendor", ramvendor)
		player:SetAttribute("RamType", ramtype)
		player:SetAttribute("MoboVendor", mobovendor)
		player:SetAttribute("MoboType", mobotype)
		player:SetAttribute("CpuVendor", cpuvendor)
		player:SetAttribute("CpuType", cputype)
		player:SetAttribute("GpuVendor", gpuvendor)
		player:SetAttribute("GpuType", gputype)
		player:SetAttribute("DriveVendor", drivevendor)
		player:SetAttribute("DriveType", drivetype)
		player:SetAttribute("NetVendor", netvendor)
		player:SetAttribute("NetType", nettype)
		player:SetAttribute("BattVendor", battvendor)
		player:SetAttribute("BattType", batttype)
		player:SetAttribute("UsedThreads", usedThreads)
		player:SetAttribute("GPUVRAMUsed", usedVRAM)
		player:SetAttribute("GPUVRAMTotal", GPUVram)
		player:SetAttribute("GPUVRAMPercent", math.floor((usedVRAM / GPUVram) * 100))


		-- Monitor for panic conditions only if not already panicked
		if not kernelPanicked then
			monitorForPanics(cpu, gpu, mem, temp, usedStorageMB, networkUsage)

			-- UI updates only if system is OK
			-- RAM UI
			memoryLabel.Text = ("Memory Usage: %s / 8 GB"):format(formatStorageAmount(ramUsage))
			memoryBar.Size = UDim2.new(math.clamp(ramUsage / maxRAM, 0, 1), 0, 0.05, 0)
			if lowRamWarningWindow then
				lowRamWarningWindow.Visible = ramUsage >= RAM_WARNING_THRESHOLD
			end

			-- Disk space warnings
			if warningWindow then
				if usedStorageMB >= lowDiskThreshold then
					warningWindow.Visible = true
					hideRandomDesktopIcons(3)
				else
					warningWindow.Visible = false
				end
			end

			-- CPU, GPU UI
			cpuLabel.Text = ("CPU Usage: %.1f%%"):format(cpu)
			cpuBar.Size = UDim2.new(math.clamp(cpu / 100, 0, 1), 0, 0.05, 0)
			gpuLabel.Text = ("GPU Usage: %.1f%%"):format(gpu)
			gpuBar.Size = UDim2.new(math.clamp(gpu / 100, 0, 1), 0, 0.05, 0)

			-- CPU Freq & Temp
			cpuFreqLabel.Text = ("CPU Frequency: %.2f GHz"):format(frequency)
			cpuTempLabel.Text = ("CPU Temp: %d°C"):format(temp)

			-- Storage
			storageLabel.Text = ("Storage Used: %s / %d GB"):format(formatStorageAmount(usedStorageMB), maxStorageGB)
			storageBar.Size = UDim2.new(math.clamp(usedStorageMB / (maxStorageGB * 1024), 0, 1), 0, 0.05, 0)

			-- Network
			networkLabel.Text = ("Network Usage: %d%%"):format(networkUsage)
			networkBar.Size = UDim2.new(math.clamp(networkUsage / 100, 0, 1), 0, 0.05, 0)

			-- DiskMenu UI update
			if diskAmount and diskBar then
				diskAmount.Text = ("%s / %d GB"):format(formatStorageAmount(usedStorageMB), maxStorageGB)
				diskBar.Size = UDim2.new(math.clamp(usedStorageMB / (maxStorageGB * 1024), 0, 1), 0, 1, 0)

				if systemUsageLabel then
					systemUsageLabel.Text = ("System Usage: %s"):format(formatStorageAmount(getSystemStorage()))
				end
				if userUsageLabel then
					userUsageLabel.Text = ("User Usage: %s"):format(formatStorageAmount(getUserCreatedStorage()))
				end
				if cacheUsageLabel then
					cacheUsageLabel.Text = ("Cache Usage: %s"):format(formatStorageAmount(getCacheStorage()))
				end
				if driveTextButton then
					driveTextButton.Text = ("(C) Local Disk (%s GB / 512GB Used)"):format(tostring(math.floor(usedStorageMB / 1024)))
				end
			end

			-- Periodic cleanup
			updateWindowTracking() -- Update tracking every few seconds

			if systemIntegrityCounter == 10 then -- after 10 seconds, validate
				systemIntegrityCounter = 0
				validateSystemIntegrity()
			end
			systemIntegrityCounter += 1
		end
		task.wait(1)
	end
end)

-- Apply button to change CPU frequency
applyButton.MouseButton1Click:Connect(function()
	local newFreq = tonumber(cpuTextBox.Text)
	if newFreq and newFreq > 0 and newFreq <= 10 then
		setFrequency(newFreq)
		-- Tell the server to save the new frequency
		cpuFrequencyUpdateRemote:FireServer(newFreq)
	else
		-- Optionally show an error message here for invalid input
	end
end)

-- Load saved CPU frequency from server
local savedFreq = cpuFrequencyRemote:InvokeServer()
if savedFreq and typeof(savedFreq) == "number" then
	setFrequency(savedFreq)
else
	setFrequency(2.4) -- fallback default
end

-- Clear cache button
if clearCacheButton then
	clearCacheButton.MouseButton1Click:Connect(function()
		cacheMB = 0
	end)
end

--task.spawn(function()
--	while not kernelPanicked do
--		validateSystemIntegrity()
--		task.wait(10)
--	end -- closes WHILE
--end)    -- closes FUNCTION

This script single handedly powered my entire game
And also single handedly imploded my Laptop and Studio when i paste it into the Script Editor

3 Likes

Can you explain what this is and does?

1 Like

This is an Kernel script in actual computers Kernel is an software for managing Processes that is apps and also manages the hardware its the core of an OS Like Linux or Windows

This script tries to emulate/simulate actual kernels

This script Calculates CPU/GPU/RAM/ and storage by certain variables such CPU Clock speed RAM amount Max storage GPU VRAM etc then if it hits certain limits it could lag or kernel panic/BSOD

The script finds frames in PlayerGUi > ScreenGUi > That has “Window” in its name then it checks an Bool value to validate if its an app window then if visible it will Calculate the effect on the Simulated Hardware such as the RAM Usage increasing CPU Overheats etc and

This script calculates Storage via PlayerGUI > ScreenGUI > DesktopFrame > Frame in Frame it finds bunch off image buttons witch is App Icons each icon visible impacts the storage

My game also has an gallery system where player could store images that also impacts the Storage

also the player could modify the CPU Clock speed for faster and higher failure rate