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

Works in Studio but not in client! What have I done wrong? [UNSOLVED]

Asked by 10 years ago

When I test out my game in Studio, it seems to work fine but then I play the game on the client via the website, the GUI's don't seem to change when I click on them. And yes, they are text Buttons and nothing else.

local Button = script.Parent
Frame = script.Parent.window2
hide = script.Parent.open
lhide = script.Parent.open

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

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

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

Button.MouseButton1Click:connect(onClick)

0
Why do you have three functions that are called by the same event? Just put it in one function. PiggyJingles 358 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago

Everytime that you make a new function named onClick() it will overwrite the other ones. That means that the first two functions are basically useless.

0
So how shall I put them into 1 function? Michael007800 144 — 10y
0
Put all of your code under the first onClick() function, and then debug it from there. TheGuyWithAShortName 673 — 10y
0
That still doesn't explain why it works in the studio and not in the game. User#348 0 — 10y
0
Because play solo is weird. TheGuyWithAShortName 673 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Try putting the code in a LocalScript. When you run the game in the studio, it all runs on your computer locally, so Scripts and LocalScripts act the same. When it is uploaded, the game runs on the server, which is different.

Also, Here is a much cleaner version of your code.

local Button = script.Parent

function onClick()
    for i, v in pairs(Button:GetChildren()) do
        if v.Visible == true then
            v.Visible == false
        else v.Visible == true --If it isn't true, it has to be false.
        end
    end
end

Button.MouseButton1Click:connect(onClick)

If you don't know how to use v in pairs, YOU MUST LEARN RIGHT NOW BECAUSE IT IS THE BEST THING IN LUA!!11!!1!!!one!!!1!!!! jk

Answer this question