Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- THIS PART IS OPTIONAL IF YOU WANT TO RUN THE SCRIPT YOURSELF!!
- 1. Place a "ScreenGui" inside of StarterGui
- 2. Inside of "ScreenGui", place a "TextButton"
- 3. Inside of "TextButton", insert a "LocalScript"
- (these steps center the gui)
- 4. Set the anchor point of the TextButton to 0.5,0.5
- 5. Set the position of the TextButton to {0.5, 0, 0.5, 0}
- ]]
- -- the getMessage() function
- function getMessage()
- -- This will pick a random number 1-3
- local number = math.random(1,3)
- if number == 1 then
- return "Hello World!"
- elseif number == 2 then
- return "Testing"
- elseif number == 3 then
- return "Functions are useful"
- end
- end
- -- the clickEvent() function
- function clickEvent()
- -- get the message and save the result to a variable
- local message = getMessage()
- -- update the text of the button with the message
- script.Parent.Text = message
- -- print the message as well
- print(message)
- end
- -- Within TextButton, there is an "event" that is fired everytime the button is clicked
- -- Using :Connect(), we can tap into that event, and execute a function we give it
- -- "Everytime TextButton is clicked, execute clickEvent()"
- script.Parent.MouseButton1Click:Connect(clickEvent)
Advertisement
Add Comment
Please, Sign In to add comment