Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you fade a group of bricks in and out using a loop?

Asked by 6 years ago

I want to fade in/out a group of bricks using a button (preferably using something like a loop). This is the script I have right now without the fade (basically turning it on):

model = game.Workspace.LIGHTS

function start ()
for _,v in pairs(model:GetChildren()) do
v.Transparency = .9
v.SpotLight.Enabled = true
v.PointLight.Enabled = true
end

script.Parent.ClickDetector.MouseClick:connect(start)

What I want to do is to have the Transparency and spotlight fade in using a loop. I know I could use this and it would basically do what I want:

model = game.Workspace.LIGHTS

function start ()
for _,v in pairs(model:GetChildren()) do
v.Transparency = .99
v.SpotLight.Enabled = true
v.PointLight.Enabled = true
wait(.001)
v.Transparency = .98
wait (.001)
v.Transparency = .97
wait (.001)
v.Transparency = .96
wait (.001)
v.Transparency = .95
v.SpotLight.Brightness = .5
wait (.001)
v.Transparency = .94
wait (.001)
v.Transparency = .93
wait (.001)
v.Transparency = .92
wait (.001)
v.Transparency = .91
wait (.001)
v.Transparency = .9
v.SpotLight.Brightness = 100
end

script.Parent.ClickDetector.MouseClick:connect(start)

The only problem with that is 1) Its a mouthful of lines 2) When it activates, it does one part of the model at the time while what I want is everything to work in sync.

If you don't understand the problem and need more clarification, let me know. Thanks!

0
for i,v in pairs (obj:GetChildren()) do abnotaddable 920 — 6y
0
and use for loops abnotaddable 920 — 6y

1 answer

Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago
Edited 6 years ago

We can use a loop to slowly increment it.

local Down = true
while wait(0.01) do -- Dont want to kill roblox with this loop ok?
    if Down then -- if we are going down
        Part.Transparney = Part.Transparency - 0.01
    else -- if we are going up
        Part.Transparency = Part.Transparency + 0.01
    end
    if Part.Transparency == 0 then -- tell script to go up
        Down = false
    elseif Part.Transparency == 1 then -- tell script to go down
        Down = true
    end
    if Part.Transparency = 0.5
        Spotlight.[NameOfPropertyHere] = 0.5 -- if you want to change every so often, or add it as part of the loop if you want it to change with.
    end
end
0
And decrease your memory and time of your program! Also, to even decrease even more your memory and time, use for loops! Woo hoo! hiimgoodpack 2009 — 6y
0
The question literally asked for a loop. Got any better idea to not use a loop even though he asked for a loop? H4X0MSYT 536 — 6y
0
sometimes I really wish I could downvote comments CootKitty 311 — 6y
Ad

Answer this question