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 8 years ago
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

Log in to vote
0
Answered by
DataStore 530 Moderation Voter
8 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.

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.

Ad

Answer this question