Still have questions? Join our Discord server and get real time help.
0

# Is there a way i can do a function for Gui fading?? Need help with a gui?

Is there a service like TweenPosition but FadeGui that I can do to fade a solid color gui into the screen? Ive tried to reseach, I cant seem to find anything. I want it to be like you see a npc that looks llike you. then it fades in a gui, says something, and then fades out. I needed to say this extra cause the server said i needed to describe my problem, just need help on a fade funtion xD

6
RayCurse 1348
1 year ago
Edited 1 year ago

Roblox has a service called TweenService which can be used for what you are asking. In fact, it can be used to tween almost any visual property such as transparency, position, and color. In order to use tween service, you first need to instantiate a TweenInfo object. Then you can pass this info into the Create() function in TweenService to get a TweenObject.

local gui = screenGui.Frame --example

--Create tween info
local easeStyle = Enum.EasingStyle.Quint
local easeDirection = Enum.EasingDirection.In
local info = TweenInfo.new(3 , easeStyle , easeDirection)

--Create goal for properties
local goal = {
Transparency = 1
BackgroundColor3 = Color3.new(1 , 1 , 1)
}

--Create tween object
local TweenService = game:GetService("TweenService")
local tween = TweenService:Create(gui , info , goal)

--Play the tween
tween:Play()

0
Ths for all your help JakePlays_TV 97 — 1y
0

I actually developed this just the other day!

This needs to be in a LocalScript

local DEFAULT_DURATION = 2 -- seconds
local RunService = game:GetService("RunService")

local function lerp(a, b, t)
return a * (1-t) + (b*t)
end

local function fade(gui, startTransparency, endTransparency, duration)
duration = duration or DEFAULT_DURATION
local elapsed = 0
while elapsed < duration do
elapsed = elapsed + (RunService.Heartbeat:Wait())
gui.BackgroundTransparency = lerp(startTransparency, endTransparency, elapsed/duration)
end
end

gui.Visible = true
end

gui.Visible = false
end


Example usage, appended at the bottom of the above script:

-- this example fades MyGui in and out twice
local myGui = game.Players.LocalPLayer.PlayerGui.ScreenGui.MyGui
-- first using the default fade time of 2 seconds
-- then using specific fade times


Bonus:

-- this example makes fading accessable via BindableFunctions
local myGui = game.Players.LocalPLayer.PlayerGui.ScreenGui.MyGui