Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't the script fade-in a part?

Hey. I'm trying to make a part smoothly fade-in but for some reason this does not work. Any ideas why? Here's the code:

local T = script.Parent
local trans = T.Transparency

while true do
	wait(5)
	trans = trans + .1
end

1 comment

0

youre telling it to wait 5 seconds inbetween every time it changes the transparency by .1, it probably does fade in but it does it too slowly?

2 answers

You can try the following. If it doesn't work, tell me the output.

local T = script.Parent
local trans = T.Transparency
	 
for i = 0,1,0.1 do
	wait(5)
	trans = i
end

3 comments

0

It doesn't change the transparency and for some reason there is literally nothing in the output except when the place is autosaving.

0

What transparency is at the start and what is the goal trasparency?

0

It's 0 and the goal is 1

That is because you are creating a variables. Here is one method you can use to solve this issue.

-- Variables

local Part = script.Parent -- The part we are going to fade - in

-- Values

local Duration = 10 -- How many seconds it takes to fade in

-- Functions

local function FadeIn() -- Function to Fade In
	local Start = tick() -- This is when the function was called
	
	while true do -- Loop
		local Now = tick() -- Get the current time
		local Difference = math.clamp(Start - Now, 0, Duration) -- Calculate how many seconds has passed
		local Ratio = (Difference / Duration) -- Get a percentage
		
		Part.Transparency = (1 - Ratio) -- Set the transparency
		
		wait() -- Small delay so that studio doesn't crash
	end
end

local function FadeOut() -- Function to Fade Out
	local Start = tick() -- This is when the function was called
	
	while true do -- Loop
		local Now = tick() -- Get the current time
		local Difference = math.clamp(Start - Now, 0, Duration) -- Calculate how many seconds has passed
		local Ratio = (Difference / Duration) -- Get a percentage
		
		Part.Transparency = Ratio -- Set the transparency
		
		wait() -- Small delay so that studio doesn't crash
	end
end

-- Misc

while true do
	FadeOut()
	
	wait(1)
	
	FadeIn()
end

3 comments

0

Same with pedroquitas1's answer, unfortunately: it doesn't change the transparency and for some reason there is literally nothing in the output except when the place is autosaving.

0

Then maybe your script is disabled

0

It's not

This discussion is preserved as it was. New answers, comments, and votes are closed.