Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

1 comment

0

Why do you have three functions that are called by the same event? Just put it in one function.

2 answers

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.

4 comments

0

So how shall I put them into 1 function?

0

Put all of your code under the first onClick() function, and then debug it from there.

0

That still doesn't explain why it works in the studio and not in the game.

0

Because play solo is weird.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.