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

Why Won't MouseButton1Click Wont Function At All?

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

5 comments

0

I changed the slide1 to slide1 = script.Parent.Parent

0

instead of :connect use :Connect

0

WideSteal321, that has no affect to the script.

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.

0

@ViceToxicZ What @incapaxian said.

1 answer

✓ Accepted answer

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

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