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

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

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!

2 comments

0

for i,v in pairs (obj:GetChildren()) do

0

and use for loops

1 answer

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

3 comments

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!

0

The question literally asked for a loop. Got any better idea to not use a loop even though he asked for a loop?

0

sometimes I really wish I could downvote comments

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