Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

GUI button to make "visible=false" a frame wont work?

Asked by
Paldi 109
8 years ago

Why this wont work?(i tried both local script and script)

function OnClicked()
    on = 1
    if on == 1 then
        on = 0
        script.Parent.Parent.Frame.Visible = false
    end
    if on == 0 then
        on = 1
        script.Parent.Parent.Frame.Visible = true
    end

end

script.Parent.MouseButton1Click:connect(OnClicked)

1 answer

Log in to vote
0
Answered by 8 years ago

Edited Ok I have it now, this should work. I just tested this in studio.

on = 1
script.Parent.MouseButton1Down:connect(function()
    if on == 1 then
        on = 0
        script.Parent.Parent.Frame.Visible = false
    elseif on == 0 then
        on = 1
        script.Parent.Parent.Frame.Visible = true
    end
end)
0
dont work either Paldi 109 — 8y
0
hmm let me try this in studio alex_ander 163 — 8y
0
huh, I just don't get it. Why would a generic function work rather than a regular one? LateralLace 297 — 8y
0
not sure why but it just works alex_ander 163 — 8y
0
It works because your "on" variable is being stored in your script environment rather than being reset every time the button is clicked. CodingEvolution 490 — 8y
Ad

Answer this question