local ui = game.StarterGui.Introduction
local TweenService = game:GetService("TweenService")
print ("hi completed.")
ui.Warning.Acknowledge.MouseButton1Down:Connect(function()
print ("button completed.")
for _, gui in pairs(ui:GetDescendants()) do
print ("descend completed.")
if not gui:IsA("TextLabel") or not gui:IsA("Frame") then continue end
print ("For completed.")
local tweenInfo = TweenInfo.new(
2, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
-1, -- RepeatCount
true, -- Reverses
0 -- DelayTime
)
TweenService:Create(gui, tweenInfo,{
Transparency = 1
}):Play()
end
end)
Any help on this is much appreciated!
I’m still learning so any advice given always helps, thank you for your time.
Are you sure your button “Acknowledge” is a TextButton? Instead try using MouseButton1Click event instead of MouseButton1Down, just for testing purposes, since I really can’t see the problem in the code?
I think the problem is when you are defining your GUI. StarterGUI is just a Service, while you are supposed to get a PlayerGUI, which is directly from a Player.
Basically StarterGUI acts as a container which holds UI. Whenever a Player joins, that UI inside of StarterGUI will clone and be placed inside of the Player’s PlayerGUI, which is an another container, but only for that one Player!!!
I recommend you to do following:
-- Services --
local Players = game:GetService("Players")
-- Variables --
local Player = Players.LocalPlayer
local PlayerUI = Player.PlayerGui
local ui = PlayerUI.Introduction
You have to reference the PlayerGui instead of the StarterGui, because StarterGui basically just clones everything from there into the PlayerGui when a player joins. Also, I’m not sure you can use “Transparency” to change the transparency of a GUI object, it’s an invalid property. So in this case, you would have to change the BackgroundTransparency for the TextLabels and Frames, and for TextLabels, you would have to change the TextTransparency.
New Code
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local Player = Players.LocalPlayer
local PlayerGUI = Player.PlayerGui
local ui = PlayerGUI.Introduction
ui.Warning.Acknowledge.MouseButton1Down:Connect(function()
for _, gui in pairs(ui:GetDescendants()) do
if not gui:IsA("TextLabel") or not gui:IsA("Frame") then continue end
local tweenInfo = TweenInfo.new(
2, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
-1, -- RepeatCount
true, -- Reverses
0 -- DelayTime
)
local goal = {
BackgroundTransparency = 1
}
if gui:IsA("TextLabel") then
goal["TextTransparency"] = 1
end
TweenService:Create(gui, tweenInfo, goal):Play()
end
end)
Thank you, this code still won’t run! I think the issue is here as it was on my prev code: if not gui:IsA("TextLabel") or not gui:IsA("Frame") then continue end
I don’t recommend creating Tweens in Events like MouseButton1Click, because every time you click on a button, you create a Tween, and that Tween is being stored somewhere as a memory address, which can eventually turn into a memory leak!
No, you don’t have to use a remote event. Also, I fixed the entire script, the issue was that you were adding a repeat count and made the tween reverse.
New Code
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local Player = Players.LocalPlayer
local PlayerGUI = Player:WaitForChild("PlayerGui")
local ui = PlayerGUI.Introduction
ui.Warning.Acknowledge.MouseButton1Down:Connect(function()
for _, gui in pairs(ui:GetDescendants()) do
if not gui:IsA("TextLabel") and not gui:IsA("Frame") then continue end
if gui:IsA("TextLabel") and gui.TextTransparency == 0 or gui:IsA("Frame") and gui.BackgroundTransparency == 0 then continue end
local tweenInfo = TweenInfo.new(
2, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out -- EasingDirection
)
local goal = {
BackgroundTransparency = 1
}
if gui:IsA("TextLabel") then
goal["TextTransparency"] = 1
end
TweenService:Create(gui, tweenInfo, goal):Play()
end
end)
EDIT: I also made an edit to this post a couple mins later, so if you immediately tested this out before I edited this message, then try re-copying the script.
Actually I think you are fine, since you are not creating a variable for your Tween:Create() and you are playing it immediately, but in the future make sure to destroy your created Tweens when you don’t need to use them, which can prevent memory leak. You don’t need to worry about it right now, but in the near future, you might.