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

Why do I get an error when doing MouseButton1Click event?

Asked by 4 years ago
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 <eof> 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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your 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)
0
Hope it works! VikkiVuk 74 — 4y
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' DevSeveral 19 — 4y
0
wait sorry my bad, ill edit the answer VikkiVuk 74 — 4y
0
Try now with the updated answer VikkiVuk 74 — 4y
View all comments (4 more)
0
First one does not work and I get no error DevSeveral 19 — 4y
0
Try now, also did you try the second script i gave you? VikkiVuk 74 — 4y
0
Hey! The first script worked but second did not but that's fine! Tysm!' DevSeveral 19 — 4y
0
Try the second script now again. VikkiVuk 74 — 4y
Ad

Answer this question