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

What's wrong with this main menu script?

local background = game.Players.PlayerGui.ScreenGui.BackGround
local Creditsbutton = game.Players.PlayerGui.ScreenGui.BackGround.CreditsButton
local TextLabel =game.Players.PlayerGui.ScreenGui.BackGround.TextLabel

function OnClicked()
	background.BackgroundTransparency = 1
	Creditsbutton.Visible = false
	TextLabel.Visible = false
end

Obviously, I want the background to become transparent when the player clicks play. Why is it not working?

1 answer

There's two issues with the script you've provided us with.

  • You've not called your 'Onclicked' function - You've not even connected it to an event.
  • There's no such player called "PlayerGui", probably.

To fix these two issues and to get the result you want, you need to connect the 'OnClicked' function to the MouseButton1Click event of the 'Play' button. You also need to get the LocalPlayer. An example fix is below.

local Player = game.Players.LocalPlayer
local Gui = Player.PlayerGui.ScreenGui
local Background = Gui.BackGround
local CreditsButton = BackGround.CreditsButton
local TextLabel = Background.TextLabel 
local PlayButton = --// You need to fill this out. 

function Clicky()
	Background.BackgroundTransparency = 1
	CreditsButton.Visible = false
	TextLabel.Visible = false
end

PlayButton.MouseButton1Click:connect(Clicky) 

Do remember that the PlayButton variable needs to be filled out and that the PlayButton should be an ImageButton or a TextButton. It should also be noted that you don't necessarily have to get the LocalPlayer - If the script is in the GUI, or is in the PlayButton, you can quite easily just parent up. However, seeing as you didn't say where it's located, I operated under the assumption that the script is outside of the GUI.

It is also worth noting that a function can be named anything you like and doesn't need to resemble the name of the event you're planning to use.

If this doesn't work, please provide what the output spits out.

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