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

What's wrong with this main menu script?

Asked by 9 years ago
1local background = game.Players.PlayerGui.ScreenGui.BackGround
2local Creditsbutton = game.Players.PlayerGui.ScreenGui.BackGround.CreditsButton
3local TextLabel =game.Players.PlayerGui.ScreenGui.BackGround.TextLabel
4 
5function OnClicked()
6    background.BackgroundTransparency = 1
7    Creditsbutton.Visible = false
8    TextLabel.Visible = false
9end

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

1 answer

Log in to vote
0
Answered by
DataStore 530 Moderation Voter
9 years ago

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.

01local Player = game.Players.LocalPlayer
02local Gui = Player.PlayerGui.ScreenGui
03local Background = Gui.BackGround
04local CreditsButton = BackGround.CreditsButton
05local TextLabel = Background.TextLabel
06local PlayButton = --// You need to fill this out.
07 
08function Clicky()
09    Background.BackgroundTransparency = 1
10    CreditsButton.Visible = false
11    TextLabel.Visible = false
12end
13 
14PlayButton.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.

Ad

Answer this question