How do I make it so when you press a button a random word will appear

Hey! Im new to Scripting on Roblox and I need help. So im making my first game which will be when you press a GUI button a random sentence will appear. I tried searching it up but cant find anything. Does anyone know how to make this?

Let’s clarify, do you need something straight random or random from a specific list?

I need a specific list with compliments given to you

You can use this:

local list = {"Bla-bla-bla", "You are top!"}
local rand = list[math.random(1, #list)] --will give a random sentence from the list
1 Like

How do you make the words appear on a TextLabel GUI when you press a GUI button?

local list = {"Bla-bla-bla", "You are top!"}
button.Activated:Connect(function() --button is your buton
	label.Text = list[math.random(1, #list)] --label is your label..
end)

Docs: UI | Roblox Creator Documentation
Creating a GUI | Roblox Creator Documentation

1 Like

Its not working even though there are no errors in the output

Please send the full your code

I would recommend using:

button.Activated:Connect(function)

instead.
This way it works on mobile

1 Like

Yes, you’re right, but I don’t think that’s the problem now.

1 Like

image

What kind of a script are you using?
This could effect it.
also where is the script?
Like in the GUI. or what?

Im just using s script inside the screenGui

And is it a local script?
Just making sure.
Im assuming it is

Its just a normal script. Is it supposed to be a local script?

You need to use not StarterGui, but PlayerGui, or put the script in the gui itself and use script.Parent
Example:

local label = script.Parent.TextLabel

Yes it should be a local script. It can only get inputs on the local side.

Also
when you get the button and label,
if the script is in the GUI then do this

local label = script.Parent.TextLabel
local button = script.Parent.TextButton 

Yes exactly what @3YbuKtOp said

local label = script.Parent.TextLabel
local button = script.Parent.TextButton
local list = {"Bla-bla-bla", "You are top!"}

button.Activated:Connect(function()
	label.Text = list[math.random(1, #list)]
end)

image

1 Like

It works now! Thank you for helping me!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.