How to make a smooth transparency fade (with parts)

  1. What is the issue?

as you can see here there a red button but, there’s also glass, now what I want is a smooth transparency fade, I already have a script to when you break it the only thing I can’t figure out is how to make it smooth (meaning when you break the glass it will reaper in a smooth transparency way.) something like that, btw if your wondering what the glass transparency it’s 0.75 so you can see the button

  1. What solutions have you tried so far? yes but never found my asnwer
local GlassTrans = script.Parent
script.Parent.ClickDetector.MouseClick:Connect(function()
	script.Parent.Position = Vector3.new(67.25, 140.7, 2)
	script.Parent.ClickDetector.MaxActivationDistance = 0
	wait(3)
	script.Parent.Position = Vector3.new(67.25, 141.2, 2)
	GlassTrans.Transparency = 1
	while true do
		wait(0.05)
		GlassTrans.Transparency = script.Parent.Transparency > 0.01 --I have also try
--using a + - > < but it sometimes seems to either it shows numbers going high up to
--like (1.50) (3.23) or even higher (10.45) which idk why it dose that as it shows it
--invisible or, it puts the transparency 0
		print("it's doing it")
		if script.Parent.Transparency == 0.75 then
			script.Parent.ClickDetector.MaxActivationDistance = 10
			print("it broke out")
		    else
			print("might have ended")
			break
		end
	end
end)

do not write entire scripts or design entire systems for you

5 Likes
while item.Transparency > 0 do
    item.Transparency -= 0.05 -- The greater this number, the less it takes to fade item
    wait(0.1) -- The the lower the number in wait(), the less time it takes to fade item
end

With the above, I’d recommend you keep the num in "item.Transparency -= num relatively small (like 0.05 or whatever works) and adjust the parameter of wait(). This way it fades in more finite adjustments, not in choppy “bulks” at a time.

6 Likes

I would use TweenService to get the smooth transparency fade done.

don’t really use TweenService and plus can it really do that?

TweenService would work, but for a simple fade you could just do this:

Yeah. I think the code should look like this

local TweenService = game:GetService("Tween Service")

local tween = TweenService:Create(object, TweenInfo.new(Amount of time) , {Transparency = 0.75})
2 Likes

ok I see but I tried his code and it works out short and easy while this piece of code looks a little long I prefer the other code but thanks you.

2 Likes