how to execute scripts when a button gui is pressed roblox

-- Step 1: Create a ScreenGui to hold the button
local gui = Instance.new("ScreenGui")
gui.Parent = game.Players.LocalPlayer.PlayerGui

-- Step 2: Create a TextButton inside the ScreenGui
local button = Instance.new("TextButton")
button.Parent = gui
button.Position = UDim2.new(0.5, -50, 0.5, -25)
button.Size = UDim2.new(0, 100, 0, 50)
button.Text = "Click me"

-- Step 3: Define the function to be executed when the button is clicked
local function onButtonClicked()
    print("Button clicked!") -- Replace this with your desired script or function
end

-- Step 4: Connect the function to the button's MouseButton1Click event
button.MouseButton1Click:Connect(onButtonClicked)