Lag testing fun script
Key RequiredUniversal

Lag testing fun script

Universal Scriptjksgaming2015jksgaming2015 810 views 39 executesUpdated Aug 20, 2025
Unrated
00
Lua Script•106 lines (3391 chars)
-- ServerScript, place in ServerScriptService
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

-- Create RemoteEvent for button clicks
local lagEvent = Instance.new("RemoteEvent")
lagEvent.Name = "LagEvent"
lagEvent.Parent = ReplicatedStorage
print("LagEvent created in ReplicatedStorage")

-- Create GUI for each player
local function createGui(player)
    print("Creating GUI for player: " .. player.Name)
    local screenGui = Instance.new("ScreenGui")
    screenGui.Name = "LagTester"
    screenGui.ResetOnSpawn = false
    screenGui.Parent = player.PlayerGui

    local button = Instance.new("TextButton")
    button.Size = UDim2.new(0, 120, 0, 40)
    button.Position = UDim2.new(0, 20, 0, 200)
    button.Text = "Start Lag"
    button.BackgroundColor3 = Color3.fromRGB(200, 50, 50)
    button.TextColor3 = Color3.new(1, 1, 1)
    button.Font = Enum.Font.SourceSansBold
    button.TextSize = 18
    button.Parent = screenGui

    local corner = Instance.new("UICorner")
    corner.CornerRadius = UDim.new(0, 10)
    corner.Parent = button

    -- Bind button click to RemoteEvent
    button.Activated:Connect(function()
        print("Button clicked by player: " .. player.Name)
        lagEvent:FireServer("toggle")
    end)

    return screenGui
end

-- Distribute GUI to players when they join
Players.PlayerAdded:Connect(function(player)
    print("Player joined: " .. player.Name)
    createGui(player)
end)

-- Distribute GUI to existing players
for _, player in ipairs(Players:GetPlayers()) do
    createGui(player)
end

-- Lag logic
local connection
local lagging = false
local function startLag()
    if not lagging then
        print("Starting lag")
        lagging = true
        connection = RunService.Heartbeat:Connect(function()
            -- Heavy math load
            for i = 1, 2e6 do
                local _ = math.sin(i) * math.cos(i)
            end
            -- Part spam
            for i = 1, 200 do
                local p = Instance.new("Part")
                p.Anchored = true
                p.CanCollide = false
                p.Size = Vector3.new(1, 1, 1)
                p.CFrame = CFrame.new(math.random(-50, 50), math.random(5, 50), math.random(-50, 50))
                p.Parent = workspace
                game:GetService("Debris"):AddItem(p, 2)
            end
        end)
        -- Update all players' GUI
        for _, player in ipairs(Players:GetPlayers()) do
            local screenGui = player.PlayerGui:FindFirstChild("LagTester")
            if screenGui then
                local button = screenGui:FindFirstChild("TextButton")
                if button then
                    button.Text = "Stop Lag"
                    button.BackgroundColor3 = Color3.fromRGB(50, 200, 50)
                end
            end
        end
    end
end

local function stopLag()
    if lagging then
        print("Stopping lag")
        if connection then
            connection:Disconnect()
            connection = nil
        end
        lagging = false
        -- Clean up parts
        for _, part in ipairs(workspace:GetChildren()) do
            if part:IsA("Part") and part.Anchored and not part.CanCollide then
                part:Destroy()
            end
        end
        -- Update all players' GUI
        for _, player in

Features & Information

Lag

Community Comments (0)

No comments yet for this script.

More Scripts for Universal Scripts