Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

I would like that when I press the sa button gives me a random link among my list in the textbox ?

Asked by 3 years ago
Edited 3 years ago

I would like that when I press the sa button gives me a random link among my list in the textbox.

Current Script (Don't work)

local links = {"link1","link2"}

game.parent.parent.buy.MouseButton1Click:Connect(function() game.parent.parent.serverhere = (math.random(#links)) end);

Photo: https://cdn.discordapp.com/attachments/848966094336819212/854111827705200700/unknown.png (serverhere is the textbox) (buy is the button)

2 answers

Log in to vote
1
Answered by 3 years ago

Hello,

Your link to the discord attachment is invalid, and you haven't provided any description of the errors, but nonetheless, I can try to help.

Firstly, there is no parent to game, so I'm not totally sure what you were attempting to reference, but I assume you mixed up game and script.

The game object refers to everything listed inside your explorer page.

The script object refers to the script the code is written in.

To fix this, we replace your references with:

script.Parent.Parent.buy
script.Parent.Parent.serverhere

Another issue in your code is your use of the random function. When assigning the value of the "serverhere" object, you assign it a number instead of a value inside your table. This is because the random function on its own only spits out random values. We need to use these random values in tandem with the table in order to get our link.

local links = {"link1","link2"}

script.Parent.Parent.buy.MouseButton1Click:Connect(function() 
    script.Parent.Parent.serverhere = links[math.random(#links)] --random object from the table
end)

Because your main post is so unclear, this is as much as I can help for now. If you re-do your post/give more information, I would be able to help you more.

I hope some of these explanations helped fix your issues!

Cheers,

Ninjamanchase

0
I was going to answer as well mine would have been similar to yours so. I just wanted to say "good answer" -Family Feud ElBamino 153 — 3y
0
:) NinjaManChase 226 — 3y
0
Its not working, I want that when I press a button, its replaces the text in a textbox with a predefined random text Millidium -2 — 3y
0
is don't work Millidium -2 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Its not working, I want that when I press a button, its replaces the text in a textbox with a predefined random text

Answer this question