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
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
.