What is the best way to tween all Screengui descendant
Example: A Close / Open Button that fades the gui in and out
2 Likes
You can simply do that, by using :GetDescendants() like this:
local _gui = script.Parent
local _tweeningframe = _gui.tweeningframe
local _button = _gui.button
local _yes = false
local _tweenservice = game:GetService('TweenService')
_tweenConfig = {
_time = 1,
easingstyle = Enum.EasingStyle.Linear,
easingdirection = Enum.EasingDirection.In
}
_button.MouseButton1Click:Connect(function()
if _yes == true then
_yes = false
for x, i in pairs(_tweeningframe:GetDescendants()) do
if i:IsA("Frame") or i:IsA("ScrollingFrame") then
_tweenservice:Create(i, TweenInfo.new(_tweenConfig._time,_tweenConfig.easingstyle,_tweenConfig.easingdirection ), {BackgroundTransparency = 1}):Play()
elseif i:IsA("TextLabel") then
_tweenservice:Create(i, TweenInfo.new(_tweenConfig._time,_tweenConfig.easingstyle,_tweenConfig.easingdirection ), {TextTransparency = 1, TextStrokeTransparency = 1}):Play()
end
end
_button.Text = "open"
_button.TextColor3 = Color3.fromRGB(0,255,0)
else
_yes = true
for x, i in pairs(_tweeningframe:GetDescendants()) do
if i:IsA("Frame") or i:IsA("ScrollingFrame") then
_tweenservice:Create(i, TweenInfo.new(_tweenConfig._time,_tweenConfig.easingstyle,_tweenConfig.easingdirection ), {BackgroundTransparency = 0}):Play()
elseif i:IsA("TextLabel") then
_tweenservice:Create(i, TweenInfo.new(_tweenConfig._time,_tweenConfig.easingstyle,_tweenConfig.easingdirection ), {TextTransparency = 0, TextStrokeTransparency = 0}):Play()
end
end
_button.Text = "close"
_button.TextColor3 = Color3.fromRGB(255,0,0)
end
end)
this code makes all the descendants of a frame visible/invisible using tweenservice.
if you might ask why of a frame, well its because if you would do like everything in a gui, it will make everything dissapear, even the close/open button as you have mentioned.
3 Likes
I have a question: Why you add _ before every variable?
Its probably something they do out of habit and I’m pretty sure it doesn’t actually do anything special (May be wrong).
1 Like
out of habit, nothing special to it.
2 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.