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
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()
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 fading local function lerp(a, b, t) return a * (1-t) + (b*t) end local function fade(gui, startTransparency, endTransparency, duration) fading = true 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 fading = false end local function fadeIn(gui, duration) while fading do wait() end gui.Visible = true fade(gui, 1, 0, duration) end local function fadeOut(gui, duration) while fading do wait() end fade(gui, 0, 1, duration) 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 fadeIn(myGui) fadeOut(myGui) -- then using specific fade times fadeIn(myGui, 5) fadeOut(myGui, 0.5)
Bonus:
-- this example makes fading accessable via BindableFunctions local myGui = game.Players.LocalPLayer.PlayerGui.ScreenGui.MyGui local fadeInBindable = myGui.FadeInBindableFunction local fadeOutBindable = myGui.FadeOutBindableFunction fadeInBindable.OnInvoke = fadeIn fadeOutBindable.OnInvoke = fadeOut