I would like to make a coding script that picks a random StringValue located inside another StringValue called Options. This is the code I have, but it is only picking the first parent inside Options.
script.Parent.Changed:connect(function(val) if val == true then local list = script.Parent.Parent.Parent.Parent.Options:GetChildren() local m = list[math.random(#list)] local n = math.random(1,2) if n == 2 then -- Coding here that has nothing to do with other functions elseif n == 1 then -- Coding here that has nothing to do with other functions end val = false end end end)
Here's where you have done your mistake.
While selecting a random value you will have to use math.random(from, to)
, You did used it, but not correctly.
For example, If I wanna choose a number btw 1 to 10 in a table like this.
local numbers = {1,2,3,4,5,6,7,8,9,10}
What I would do is
local numbers = {1,2,3,4,5,6,7,8,9,10} local random = numbers[math.random(1, #numbers)] -- Here, I am selecting the table called numbers and then selecting a random number
Here's how the script should look like
script.Parent.Changed:connect(function(val) if val == true then local list = script.Parent.Parent.Parent.Parent.Options:GetChildren() local m = list[math.random(1,#list)] local n = math.random(1,2) if n == 2 then -- Coding here that has nothing to do with other functions elseif n == 1 then -- Coding here that has nothing to do with other functions end val = false end end end)
Hope that helps :D