Well first, you should put your code into code block, there is a button with lua icon for that, should create this:
your code here
~~~~~~
But to your question, i see you are doing
local random1 = math.random(1,2)
local random2 = math.random(1,2)
if math.random(2, 2) then ...
Which line 4 has nothing to do with 2 previous variables you created, `math.random(2, 2)` will always return 2.
Instead you should check the variable:
if random1 == 1 then ...
So you could do something like this:
if random1 == 1 then
game.StarterGui.kl.ok.Visible = true
else -- random is not 1, so it's obviously 2
game.StarterGui.kl.ok.Visible = false
end
This should work but here is also a cool way of doing it by using `and` and `or` statements, here is example in your case, you can just do this in one line and it will work.
game.StarterGui.kl.ok.Visible = (random1 == 1 and true) or false
Here is what will happen, first, it will check if random1 is 1, if it is then it will set the visible to true but if not, then it will jump to the or statement and set it to false.
Another issue why yours could not be working is because the gui object has not loaded yet, this is what [WaitForChild](https://developer.roblox.com/en-us/api-reference/function/Instance/WaitForChild) is for, it is used on Gui object almost all the time. If that is the case then error could be something like `Attempt to index nil with ...`.
1 comment
dont mind that script this is the one local rand2 = math.random(1,2) print(rand2) if math.random(2) then print(rand2) wait(1) game.StarterGui.kl.ok.visible = false end