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

Button not activating the script, what do I do?

Asked by 3 years ago
local Menu = game.StarterGui.Buttons.Frame
local CloseButton = game.StarterGui.Buttons.CloseButton

function leftClick()

    Menu.BackgroundTransparency = 0.9
    wait(0.4)

    Menu.Visible = false
end

script.Parent.MouseButton1Click:Connect(leftClick)

This is my script. What I'm trying to do is make the GUI become slightly more transparent than it already was (which was at 0.8), before becoming invisible. When I test it in-game it doesn't do anything. What can I do to fix this?

3 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You are trying to set transparency IN starterGui NOT playerGui

See https://scriptinghelpers.org/blog/common-mistakes#PlayerGui for more relating to common mistakes made by a beginner. This link will direct you to "StarterGui and PlayerGui; Not the Same" Section

If you want code that is fixed then you can copy this code anyway

== Fixed Code ==

local Menu = script.Parent.Parent
local CloseButton = script.Parent.Parent.CloseButton

function leftClick()

    Menu.BackgroundTransparency = 0.9
    wait(0.4)

    Menu.Visible = false
end

script.Parent.MouseButton1Click:Connect(leftClick)

NOTE: THIS IS ASSUMING THE HIERARCHY FOLLOWING DOWN BELOW

-- ScreenGui <-- ??? (Possibly: ScreenGui) (Unknown name, so I used un-renamed name)

---- Button <-- Frame

------ CloseButton <-- ??? (Possibly: TextButton)

------ TextButton <-- TextButton (Unknown name, so I used un-renamed name)

-------- LocalScript <-- Here

Ad
Log in to vote
0
Answered by 3 years ago
local Frame = -- Add the frame directory here
local Button = -- Add the button directory here

Button.MouseButton1Click:Connect(function()
-- Insert code here

try this, it always worked for me

0
This didn't work for me nesnotnAGamesHD 2 — 3y
Log in to vote
0
Answered by 3 years ago
local Menu=script:FindFirstAncestorOfClass"ScreenGui"

Answer this question