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

Why Won't MouseButton1Click Wont Function At All?

Asked by 5 years ago

For some reason, I can't make my MouseButton1Click script work on a local script. I can't use a normal script because it will trigger to the server and not the client. Here is the code to tell me what I did wrong.

My Locations are under the code.


local slide1 = script.Parent.Parent.Parent local slide2 = game.StarterGui.TutorialGUI.Frame2 script.Parent.MouseButton1Click:connect(function() if slide2.Visible == false then slide2.Visible = true else slide2.Visible = false end end)

Script.Parent = TextButton

Script.Parent.Parent = Frame1

Script.Parent.Parent.Parent = TutorialGui

game.StarterGUI.TutorialGui.Frame2 = Frame2

0
I changed the slide1 to slide1 = script.Parent.Parent User#25920 0 — 5y
0
instead of :connect use :Connect WideSteal321 773 — 5y
0
WideSteal321, that has no affect to the script. xJigoku 17 — 5y
0
It might not affect now. But it is possible in the future. The former is deprecated in favour of the latter, and because of that the former should no longer be used. User#24403 69 — 5y
0
@ViceToxicZ What @incapaxian said. WideSteal321 773 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago

StarterGui and PlayerGui

The StarterGui is what the PlayerGui clones out of when the player spawns. So any GUIs that the player sees, are the GUIs in PlayerGui, and any LocalScripts in StarterGui are cloned into the PlayerGui and they are running in there. To fix your issue, just change the game.StarterGui.TutorialGUI.Frame2 to game:GetService("Players").LocalPlayer.PlayerGui.TutorialGUI.Frame2

local slide1 = script.Parent.Parent.Parent
local slide2 = game:GetService("Players").LocalPlayer.PlayerGui.TutorialGUI.Frame2

script.Parent.Activated:Connect(function()
    slide2.Visible = not slide2.Visible
end)


You can omit the if statement with that single line of code. not reverses a boolean, so say the current visibility was true, the Visible property would be set to not true, which is false, and if the visibility is false, the Visible property would be set to not false, which is true.

Finally, use Activated over MouseButton1Click, and :connect is deprecated, use :Connect.


I noticed you are new to the site. If this helped you out, hit that "Accept Answer" button which should be under this answer.

Ad

Answer this question