I am aiming to make my menu disappear when a button inside of it is clicked, and I would like to use a CanvasGroup for this.
My click script does not seem to work.
local TweenService = game:GetService("TweenService")
local gui = script.Parent
local canvasGroup = gui:FindFirstChild("CanvasGroup")
-- Set the initial alpha value to 1 (fully visible)
canvasGroup.Alpha = 1
-- Define the tween info for the animation
local tweenInfo = TweenInfo.new(
0.5, -- Duration of the tween
Enum.EasingStyle.Quad, -- Easing style of the tween
Enum.EasingDirection.Out -- Easing direction of the tween
)
-- Define the goal properties for the tween
local goal = {
Alpha = 0 -- Target alpha value (fully transparent)
}
-- Create the tween
local tween = TweenService:Create(canvasGroup, tweenInfo, goal)
-- Connect the MouseButton1Click event
gui.Activated:Connect(function()
-- Play the tween to make the instances inside the CanvasGroup invisible
tween:Play()
end)
I have tried to use an in pairs loop but it turned out to be quite messy, and I wanted to try the canvas group as it is apparently easier and can manipulate all it’s children.
Anyone got an idea how I can fix this?
Thanks!
The script you’re using here seems to be made using chatGPT, please don’t use that to make scripts because it sucks at it
here is an updated script that should work
local TweenService = game:GetService("TweenService")
local gui = script.Parent
local canvasGroup = gui:FindFirstChild("CanvasGroup")
-- Set the initial alpha value to 1 (fully visible)
canvasGroup.GroupTransparency = 1
-- Define the tween info for the animation
local tweenInfo = TweenInfo.new(
0.5, -- Duration of the tween
Enum.EasingStyle.Quad, -- Easing style of the tween
Enum.EasingDirection.Out -- Easing direction of the tween
)
-- Define the goal properties for the tween
local goal = {
GroupTransparency = 0 -- Target alpha value (fully transparent)
}
-- Create the tween
local tween = TweenService:Create(canvasGroup, tweenInfo, goal)
-- Connect the MouseButton1Click event
gui.MouseButton1Click:Connect(function()
-- Play the tween to make the instances inside the CanvasGroup invisible
tween:Play()
end)
i’ve changed Alpha to GroupTransparency as alpha doesn’t exist,
and to check if the button is clicked you use MouseButton1Click