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

Button not activating the script, what do I do?

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

✓ Accepted answer

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

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

1 comment

0

This didn't work for me

local Menu=script:FindFirstAncestorOfClass"ScreenGui"

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