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

Script that loops and changes the transparency of an object one by one?

ok so like i have this script right and it plays the decals and makes it a video then it looks pretty good but its really really time consuming ~~~~~~~~~~~~~~~~~ function onClicked() script.Parent.Parent.one.Transparency=0 wait(0.16) script.Parent.Parent.one.Transparency=1 script.Parent.Parent.two.Transparency=0 wait(0.16) script.Parent.Parent.two.Transparency=1 script.Parent.Parent.three.Transparency=0 wait(0.16) script.Parent.Parent.three.Transparency=1 script.Parent.Parent.four.Transparency=0 wait(0.16) script.Parent.Parent.four.Transparency=1 script.Parent.Parent.five.Transparency=0 wait(0.16) script.Parent.Parent.five.Transparency=1 script.Parent.Parent.six.Transparency=0 wait(0.16) script.Parent.Parent.six.Transparency=1 script.Parent.Parent.seven.Transparency=0 wait(0.16) script.Parent.Parent.seven.Transparency=1 script.Parent.Parent.eight.Transparency=0 wait(0.16) script.Parent.Parent.eight.Transparency=1 script.Parent.Parent.nine.Transparency=0 wait(0.16) script.Parent.Parent.nine.Transparency=1 script.Parent.Parent.ten.Transparency=0 wait(0.16) script.Parent.Parent.ten.Transparency=1 script.Parent.Parent.eleven.Transparency=0 wait(0.16) script.Parent.Parent.eleven.Transparency=1 script.Parent.Parent.twelve.Transparency=0 wait(0.16) script.Parent.Parent.twelve.Transparency=1 script.Parent.Parent.thirteen.Transparency=0 wait(0.16) script.Parent.Parent.thirteen.Transparency=1 script.Parent.Parent.fourteen.Transparency=0 wait(0.16) script.Parent.Parent.fourteen.Transparency=1 script.Parent.Parent.fifteen.Transparency=0 wait(0.16) script.Parent.Parent.fifteen.Transparency=1 script.Parent.Parent.sixteen.Transparency=0 wait(0.16) script.Parent.Parent.sixteen.Transparency=1 script.Parent.Parent.seventeen.Transparency=0 wait(0.16) script.Parent.Parent.seventeen.Transparency=1 script.Parent.Parent.eighteen.Transparency=0 wait(0.16) script.Parent.Parent.eighteen.Transparency=1 script.Parent.Parent.nineteen.Transparency=0 wait(0.16) script.Parent.Parent.nineteen.Transparency=1 script.Parent.Parent.twenty.Transparency=0 wait(0.16) script.Parent.Parent.twenty.Transparency=1 script.Parent.Parent.twentyone.Transparency=0 wait(0.16) script.Parent.Parent.twentyone.Transparency=1 script.Parent.Parent.twentytwo.Transparency=0 wait(0.16) script.Parent.Parent.twentytwo.Transparency=1 script.Parent.Parent.twentythree.Transparency=0 wait(0.16) script.Parent.Parent.twentythree.Transparency=1 script.Parent.Parent.twentyfour.Transparency=0 wait(0.16) script.Parent.Parent.twentyfour.Transparency=1 script.Parent.Parent.twentyfive.Transparency=0 wait(0.16) script.Parent.Parent.twentyfive.Transparency=1 script.Parent.Parent.twentysix.Transparency=0 wait(0.16) script.Parent.Parent.twentysix.Transparency=1 script.Parent.Parent.twentyseven.Transparency=0 wait(0.16) script.Parent.Parent.twentyseven.Transparency=1 script.Parent.Parent.twentyeight.Transparency=0 wait(0.16) script.Parent.Parent.twentyeight.Transparency=1 script.Parent.Parent.twentynine.Transparency=0 wait(0.16) script.Parent.Parent.twentynine.Transparency=1 script.Parent.Parent.thirty.Transparency=0 wait(0.16) script.Parent.Parent.thirty.Transparency=1 script.Parent.Parent.thirtyone.Transparency=0 wait(0.16) script.Parent.Parent.thirtyone.Transparency=1 script.Parent.Parent.thirtytwo.Transparency=0 wait(0.16) script.Parent.Parent.thirtytwo.Transparency=1 script.Parent.Parent.thirtythree.Transparency=0 wait(0.16) script.Parent.Parent.thirtythree.Transparency=1 script.Parent.Parent.thirtyfour.Transparency=0 wait(0.16) script.Parent.Parent.thirtyfour.Transparency=1 script.Parent.Parent.thirtyfive.Transparency=0 wait(0.16) script.Parent.Parent.thirtyfive.Transparency=1 script.Parent.Parent.thirtysix.Transparency=0 wait(0.16) script.Parent.Parent.thirtysix.Transparency=1 script.Parent.Parent.thirtyseven.Transparency=0 wait(0.16) script.Parent.Parent.thirtyseven.Transparency=1 script.Parent.Parent.thirtyeight.Transparency=0 wait(0.16) script.Parent.Parent.thirtyeight.Transparency=1 script.Parent.Parent.thirtynine.Transparency=0 wait(0.16) script.Parent.Parent.thirtynine.Transparency=1 script.Parent.Parent.forty.Transparency=0 wait(0.16) script.Parent.Parent.forty.Transparency=1 script.Parent.Parent.fortyone.Transparency=0 wait(0.16) script.Parent.Parent.fortyone.Transparency=1 script.Parent.Parent.fortytwo.Transparency=0 wait(0.16) script.Parent.Parent.fortytwo.Transparency=1 end script.Parent.ClickDetector.MouseClick:connect(onClicked)


so like yeah i was wondering if there was a way for only a few lines of code to go through every decal in the brick and change the transparancy from 0 to one and wait in between and loop for every decal then end once there is no more decals to scan and do

2 comments

0

yikes, mind if you use a loop? heres a link:

1 answer

✓ Accepted answer

Here's all I can think of by your explanation

-- >> New code
local decals = script.Parent.Parent:GetChildren()

script.Parent.ClickDetector.MouseClick:Connect(function()
	for i = 1, #decals do
		script.Parent.Parent[i].Transparency = 1
		wait(0.16)
	end
end)

-- >> Old Code
--[[
script.Parent.ClickDetector.MouseClick:Connect(function()
	for _,v in pairs(workspace.Brick:GetChildren()) do -- loops through the brick
		if v:IsA("Decal") then -- ensures its a decal
			v.Transparency = 1 -- changes the transparency
			wait(0.16) -- waits the set time
		end
	end
end)
]]

5 comments

0

no i mean like so say there is 42 decals in a brick they are all transparent i want it to take the first one make it visible then make it invisible and then go to the next until their is no more decals so then it looks like it played a video

0

Then have them numbered, dont name them out, if you could do that and update it, I could help you out

0

Updated

0

le epic thanks

0

Mind marking as solution then?

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