|
If you animate your gui's transparency like this:
script.Parent.BackgroundTransparency = .1
wait(.1)
script.Parent.BackgroundTransparency = .2
wait(.1)
script.Parent.BackgroundTransparency = .3
wait(.1)
script.Parent.BackgroundTransparency = .4
wait(.1)
script.Parent.BackgroundTransparency = .5
etc.,
then you're doing something completely inefficient and unnecessary.
let's use a while loop, it's not exactly the best way, but it's certainly better than slowly bumping it up manually
try this out:
-------------------------------
local transparency = 0
while wait() and transparency <=1 tdo
transparency = transparency + .05
script.Parent.BackgroundTransparency = transparency
end
-------------------------------
That code is basically saying:
keep adding to the transparency and set the backgroundtransparency's value to it until it is at or above one.
Works perfectly.
you can make the above script go slower by either decreasing the transparency change increment from .05 to .25, or by increasing the wait. Increasing the wait would result in a much choppier final product if you do take that path.
Now, I'll show you, in my opinion, one of the most professional-looking, most efficient ways to do this.
We'll be using a for loop.
If you have no idea how to properly write a for loop, I'll explain it after.
Try this code out:
--------------------------------
for transparency = 0, 1.05, .05 do
wait()
script.Parent.BackgroundTransparency = transparency
end
--------------------------------
it's basically the while over again, just more condensed, and much, much easier to read.
(explaining the for:
transparency is a variable we set on the commencing line of the loop
1 is the value it will break the loop at
.05 is what it's going up by
basically 0 + .05 until transparency == 1)
If I'm not too lazy and finish my essay, I'll make more of these if I get positive feedback
Happy scripting, fellas
-your friendly neighborhood scripter |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
for i = 0,1,0.1 do
thing.BackgroundTransparency = i
end |
|
|
i had a typo in the for loop, replace "tdo" with "do"
i apologize for that
-your friendly neighborhood scripter |
|
x_oJoin Date: 2015-06-04 Post Count: 4378 |
or if you want to do it properly
local start, t = tick(), 2
local startTrans = obj.Transparency
local dif = newTransparency - startTrans
repeat
renderstepped:wait()
local alpha = math.min((tick() - start) / t, 1)
obj.Transparency = startTrans + dif * alpha
until alpha == 1
"generic skids with romantic ideas about the use of OOP" ~ lordrambo |
|
|
well that's just cancer to the eyes buddy
-your friendly neighborhood scripter |
|
x_oJoin Date: 2015-06-04 Post Count: 4378 |
now it looks nicer
local function LerpNumber(obj, prop, new, t)
local renderStepped = game:GetService("RunService").RenderStepped
local startTick, startProp, dif = tick(), obj[prop], new - obj[prop]
repeat
renderStepepd:wait()
local alpha = math.min((tick() - startTick) / t, 1)
obj[prop] = startProp + dif * alpha
until alpha == 1
end
LerpNumber(workspace.Part, "Transparency", 1, 2)
"remotes? you must be a comedian" ~ dermon |
|
|
talking about unnecessary wastes of time
if you write your code like that then you really need this article
unless you're just of of those guys who likes to over-complicate their programs' source code
-your friendly neighborhood scripter |
|
x_oJoin Date: 2015-06-04 Post Count: 4378 |
How is it unnecessary or a waste of time?
I think it's beautiful <3
"generic skids with romantic ideas about the use of OOP" ~ lordrambo |
|
|
well of course it looks amazing, but if you could get a near or the same result with a more condensed code, might as well use it
-your friendly neighborhood scripter |
|
x_oJoin Date: 2015-06-04 Post Count: 4378 |
just 'cause it's condensed doesn't mean it's better
"I've always wanted to ger paid" ~ LKK |
|
|
each have the same outcome son lol
-your friendly neighborhood scripter |
|
AovisJoin Date: 2012-09-23 Post Count: 3094 |
--Activate Police Lights
while wait(.1) do
script.Parent.BackgroundTransparency = 0.001;
wait(.1)
script.Parent.BackgroundTransparency = 0.002;
wait(.1)
script.Parent.BackgroundTransparency = 0.003;
wait(.1)
script.Parent.BackgroundTransparency = 0.004;
wait(.1)
script.Parent.BackgroundTransparency = 0.005;
wait(.1)
script.Parent.BackgroundTransparency = 0.006;
wait(.1)
script.Parent.BackgroundTransparency = 0.007;
wait(.1)
script.Parent.BackgroundTransparency = 0.008;
wait(.1)
script.Parent.BackgroundTransparency = 0.009;
wait(.1)
script.Parent.BackgroundTransparency = 0.010;
wait(.1)
script.Parent.BackgroundTransparency = 0.020;
wait(.1)
script.Parent.BackgroundTransparency = 0.030;
wait(.1)
script.Parent.BackgroundTransparency = 0.040;
wait(.1)
script.Parent.BackgroundTransparency = 0.050;
wait(.1)
script.Parent.BackgroundTransparency = 0.060;
wait(.1)
script.Parent.BackgroundTransparency = 0.070;
wait(.1)
script.Parent.BackgroundTransparency = 0.080;
wait(.1)
script.Parent.BackgroundTransparency = 0.090;
wait(.1)
script.Parent.BackgroundTransparency = 0.100;
wait(.1)
script.Parent.BackgroundTransparency = 0.200;
wait(.1)
script.Parent.BackgroundTransparency = 0.300;
wait(.1)
script.Parent.BackgroundTransparency = 0.400;
wait(.1)
script.Parent.BackgroundTransparency = 0.500;
wait(.1)
script.Parent.BackgroundTransparency = 0.600;
wait(.1)
script.Parent.BackgroundTransparency = 0.700;
wait(.1)
script.Parent.BackgroundTransparency = 0.800;
wait(.1)
script.Parent.BackgroundTransparency = 0.900;
wait(.1)
script.Parent.BackgroundTransparency = 1.000;
wait(.1)
script.Parent.BackgroundTransparency = 0.001;
wait(.1)
script.Parent.BackgroundTransparency = 0.002;
wait(.1)
script.Parent.BackgroundTransparency = 0.003;
wait(.1)
script.Parent.BackgroundTransparency = 0.004;
wait(.1)
script.Parent.BackgroundTransparency = 0.005;
wait(.1)
script.Parent.BackgroundTransparency = 0.006;
wait(.1)
script.Parent.BackgroundTransparency = 0.007;
wait(.1)
script.Parent.BackgroundTransparency = 0.008;
wait(.1)
script.Parent.BackgroundTransparency = 0.009;
wait(.1)
script.Parent.BackgroundTransparency = 0.010;
wait(.1)
script.Parent.BackgroundTransparency = 0.020;
wait(.1)
script.Parent.BackgroundTransparency = 0.030;
wait(.1)
script.Parent.BackgroundTransparency = 0.040;
wait(.1)
script.Parent.BackgroundTransparency = 0.050;
wait(.1)
script.Parent.BackgroundTransparency = 0.060;
wait(.1)
script.Parent.BackgroundTransparency = 0.070;
wait(.1)
script.Parent.BackgroundTransparency = 0.080;
wait(.1)
script.Parent.BackgroundTransparency = 0.090;
wait(.1)
script.Parent.BackgroundTransparency = 0.100;
wait(.1)
script.Parent.BackgroundTransparency = 0.200;
wait(.1)
script.Parent.BackgroundTransparency = 0.300;
wait(.1)
script.Parent.BackgroundTransparency = 0.400;
wait(.1)
script.Parent.BackgroundTransparency = 0.500;
wait(.1)
script.Parent.BackgroundTransparency = 0.600;
wait(.1)
script.Parent.BackgroundTransparency = 0.700;
wait(.1)
script.Parent.BackgroundTransparency = 0.800;
wait(.1)
script.Parent.BackgroundTransparency = 0.900;
wait(.1)
script.Parent.BackgroundTransparency = 1.000;
wait(.1)
end
------------
Inefficient? no... dirty? yes... |
|
|
well darbles method is more versatile and not neccesarily slower. Didnt darble help make stealth? |
|
|
inefficient? yes... dirty? yes...
-your friendly neighborhood scripter |
|
AovisJoin Date: 2012-09-23 Post Count: 3094 |
A few years ago before I learned how to script, I made a txt file with what I pasted up there, so it's not really inefficient at, your typical copy/paste takes 2 seconds... I just feel bad for my game having to read all that crap |
|