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

Why do I get an error when doing MouseButton1Click event?

local Space = game.StarterGui.ScreenGui.Space
local SecondFrame = game.StarterGui.ScreenGui.SecondFrame

MouseButton1Click:Connect(function()
	Space.Visible = false
	SecondFrame.Visible = true
end

Error: Players.DevSeveral.PlayerGui.ScreenGui.TextButton.LocalScript:7: Expected ')' (to close '(' at line 4), got Layout:https://i.gyazo.com/bfe052345f8d803d98ac68945fc18fcc.png

I am trying to make it when someone clicks that button the Frame becomes not visible and another one becomes visible

The frame I want to be not invisible is 'Space' and the one I want to be visible is 'SecondFrame'

1 answer

✓ Accepted answer

Try this:

local Space = script.Parent.Parent.Space
local SecondFrame = script.Parent.Parent.SecondFrame 

function onClick()
	Space.Visible = false
	SecondFrame.Visible = true
end

script.Parent.MouseButton1Click:connect(onClick)

Or if you want to make it so that when you click it shows, and when you click again it disappears

local Space = script.Parent.Parent.Space
local SecondFrame = script.Parent.Parent.SecondFrame 

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

	if SecondFrame.Visible == false then
		SecondFrame.Visible = true
	elseif  SecondFrame.Visible == true then
		SecondFrame.Visible = false
	end
end

script.Parent.MouseButton1Click:connect(onClick)

8 comments

0

Hope it works!

0

for the first script I got this, 14:22:16.804 - Players.DevSeveral.PlayerGui.ScreenGui.TextButton.LocalScript:9: attempt to index nil with 'MouseButton1Click'

0

wait sorry my bad, ill edit the answer

0

Try now with the updated answer

0

First one does not work and I get no error

0

Try now, also did you try the second script i gave you?

0

Hey! The first script worked but second did not but that's fine! Tysm!'

0

Try the second script now again.

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