Currently working on a game’s fading in and out system with proximity prompts, however the frame doesn’t go away & you can’t fade in/out again.
Probably an easy fix, but I can’t seem to figure it out.
game.ReplicatedStorage.ClientEvents.Gui.FadeIn.OnClientEvent:Connect(function(plr)
script.Parent.Visible = true
repeat wait(0.07)
script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency + 0.05
until script.Parent.BackgroundTransparency == 1
script.Parent.Visible = false
end)
This is the fade-in, the fadeout isn’t much different.
The proximity prompt script
script.Parent.Triggered:Connect(function(plr)
game.ReplicatedStorage.ClientEvents.Gui.FadeIn:FireClient(plr)
end)
1 Like
Fixed it, just took a simple change on the repeat wait until to add a >= instead of a ==
Just adding this because I’m already here. TweenService is better used for a smooth fade on almost anything (unless you mean for the fade to be choppier than necessary for design purposes).
1 Like
Thank you! I’ll look into it but I haven’t used tweenservice before. I’ll have to go check it out at some point.
Very simple service to use.
This code will essentially accomplish the same thing as your first code block.
local t = 10 -- where t is how long the tween takes to reach its goal
local TweenService = game:GetService("TweenService")
game.ReplicatedStorage.ClientEvents.Gui.FadeIn.OnClientEvent:Connect(function(plr)
script.Parent.Visible = true
TweenService:Create(script.Parent, TweenInfo.new(t), {BackgroundTransparency = 0}):Play()
script.Parent.Visible = false
end)
For further understanding a tween requires an instance, a TweenInfo index, and a table of what the tween’s goal is. TweenInfo can take more arguments than just time as well. Once created you just play it like an animation.
1 Like