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

OpenClose a gui TextButton is not working in game, but it works in studio?

Asked by 5 years ago

I have made an Open/Close a GUI button for my Shop GUI. For some reason, when I click the button in studio it opens the frame. In-game and in team test it does not. Please help. This is the code I used:

local Button = script.Parent
Box = script.Parent.Parent.ScrollingFrame

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

Button.MouseButton1Click:connect(onClick)
0
is this in a server script? herrtt 387 — 5y
0
It is in a regular script inside a TextButton. ChasingNachos 133 — 5y
0
Put it in a localscript herrtt 387 — 5y

2 answers

Log in to vote
0
Answered by
green271 635 Moderation Voter
5 years ago

Since it turns visible in studio but not in game, that means you're most likely using a script for this. Scripts can't run in the PlayerGui, so you'll have to use a localscript.

Ad
Log in to vote
0
Answered by
herrtt 387 Moderation Voter
5 years ago

local Box = script.Parent.Parent:WaitForChild(”ScrollingFrame”) As things may not have loaded yet, the script will be broken, you should almost always use WaitForChild(), and second, this will only work in a local script as a ServerScript cant access the playergui

Answer this question