Francois van Kempen
Francois van Kempen

Reputation: 144

TextButton not opening Frame

So I have a simple text button inside of a ScreenGui with the following lua code.

local Button = script.Parent
local Frame = script.Parent.Parent.Frame

function onClick()
    if Frame.Visible == false then
        Frame.Visible = true
    elseif Frame.Visible == true then
        Frame.Visible = false
    end
    end

Button.MouseButton1Click:Connect(onClick)

However, when I click on the button, the frame does not show up.

The frame is set to not be visible by default.

The button is set to active, visible and selectable.

Upvotes: 0

Views: 335

Answers (4)

Chris Lallo
Chris Lallo

Reputation: 320

Just as a note, when you're doing logic like:

if button.Visible == true then button.Visible = false

You can simplify the code by writing

button.Visible = not button.Visible

I would answer the rest of the question, but you've already accepted one!

Upvotes: 0

Francois van Kempen
Francois van Kempen

Reputation: 144

I'm a bit stupid. Upon posting this question, I attempted to do some more reaserach. I found out that it might be the type of script causing it, and it was. You need to use a localscript for things like these.

Thanks anyways!

Upvotes: 0

Taazar
Taazar

Reputation: 1505

If you add in print("Testing") right after the function starts:

function onClick()
    print("Testing")
    if Frame.Visible == false then

and then run the code to make sure your onClick() function is actually being called.

If the code it called it'll print "Testing" and if it doesn't print then you know your code was just never run.

Upvotes: 1

Universal Link
Universal Link

Reputation: 307

Try with a clean script changing the Frame to visible. To check if your syntax is correct. I.e.:

local Frame = script.Parent.Parent.Frame
Frame.Visible = true

If it still doesn't work, try removing the elseif. I've had issues with scripts before just not liking the elseif command. You can just put else and it will do exactly the same job.

Upvotes: 2

Related Questions