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)
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
Its not working, I want that when I press a button, its replaces the text in a textbox with a predefined random text