Guest User

Untitled

a guest
Aug 14th, 2025
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. --[[
  2. THIS PART IS OPTIONAL IF YOU WANT TO RUN THE SCRIPT YOURSELF!!
  3.  
  4. 1. Place a "ScreenGui" inside of StarterGui
  5. 2. Inside of "ScreenGui", place a "TextButton"
  6. 3. Inside of "TextButton", insert a "LocalScript"
  7. (these steps center the gui)
  8. 4. Set the anchor point of the TextButton to 0.5,0.5
  9. 5. Set the position of the TextButton to {0.5, 0, 0.5, 0}
  10.  
  11. ]]
  12.  
  13. -- the getMessage() function
  14. function getMessage()
  15.     -- This will pick a random number 1-3
  16.     local number = math.random(1,3)
  17.  
  18.     if number == 1 then
  19.         return "Hello World!"
  20.     elseif number == 2 then
  21.         return "Testing"
  22.     elseif number == 3 then
  23.         return "Functions are useful"
  24.     end
  25. end
  26.  
  27. -- the clickEvent() function
  28. function clickEvent()
  29.     -- get the message and save the result to a variable
  30.     local message = getMessage()
  31.  
  32.     -- update the text of the button with the message
  33.     script.Parent.Text = message
  34.     -- print the message as well
  35.     print(message)
  36. end
  37.  
  38. -- Within TextButton, there is an "event" that is fired everytime the button is clicked
  39. -- Using :Connect(), we can tap into that event, and execute a function we give it
  40. -- "Everytime TextButton is clicked, execute clickEvent()"
  41. script.Parent.MouseButton1Click:Connect(clickEvent)
Advertisement
Add Comment
Please, Sign In to add comment