Problem with making tables items random visible

I want to make like on of these tables items go invisble like random NOT same everytime.

I dont know excactly how to do it so I ask if someone can help?

Everything works but the random doesn¨t do PLEASE help thank you!

local frame = script.Parent.Parent.GameFrame
local b1 = script.Parent.Parent.GameFrame.Button1
local b2 = script.Parent.Parent.GameFrame.Button2
local b3 = script.Parent.Parent.GameFrame.Button3
local openbutton = script.Parent

local mytable = {b1, b2, b3}

if openbutton.MouseButton1Click:Connect(function()
		frame.Visible = true
	end)
then
	for i, v in pairs(mytable) do
		v.Visible = #Random.new(mytable)
		
	end
end

I don’t understand what you mean. Could you clarify it more?

Do you mean like a random table object disappears when you click a button?

1 Like

Hello, you can use math.random() to get a random number between 1 and the max index of the table, and then get that value in the table, It would be something like this:

local Choosen = mytable[math.random(1, #mytable)]
Choosen.Visible = false

I also don’t see the reason you’re using the if statement on the connection?
Just put all the code inside the connection.
The script:

local frame = script.Parent.Parent.GameFrame
local b1 = script.Parent.Parent.GameFrame.Button1
local b2 = script.Parent.Parent.GameFrame.Button2
local b3 = script.Parent.Parent.GameFrame.Button3
local openbutton = script.Parent

local mytable = {b1, b2, b3}

openbutton.MouseButton1Click:Connect(function()
	frame.Visible = true
	
	local Choosen = mytable[math.random(1, #mytable)]
	Choosen.Visible = false
end)
1 Like