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
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
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
It doesn't change the transparency and for some reason there is literally nothing in the output except when the place is autosaving.
What transparency is at the start and what is the goal trasparency?
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
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.
Then maybe your script is disabled
It's not
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
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?