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

Scripting Help: How to loop this function?

--yellow on
ELights1 = Game.Workspace.[BUS MODEL].Light1.Light.Disabled = false
ELights2 = Game.Workspace.[BUS MODEL].Light2.Light.Disabled = false
ELights3 = Game.Workspace.[BUS MODEL].Light3.Light.Disabled = false
ELights4 = Game.Workspace.[BUS MODEL].Light4.Light.Disabled = false
DLights1 = Game.Workspace.[BUS MODEL].Light1.Light.Disabled = true
DLights2 = Game.Workspace.[BUS MODEL].Light2.Light.Disabled = true
DLights3 = Game.Workspace.[BUS MODEL].Light3.Light.Disabled = true
DLights4 = Game.Workspace.[BUS MODEL].Light4.Light.Disabled = true


function onClick(mouse)
ELights1
ELights2
wait(0.3)
DLights1
DLights2
ELights3
ELights4
wait(0.3)
DLights3
DLights4

end
script.Parent.MouseButton1Click:connect(onClick)

Hello! As I am fairly new to creating loops, I would like to know how to insert a loop into the function to repeat it for a set amount of time.

Ignore [BUS MODEL] as I am at school and the model is not in front of me at this moment.

1 answer

✓ Accepted answer

Explanation in chat.

--yellow on
ELights1 = Game.Workspace.[BUS MODEL].Light1.Light.Disabled = false
ELights2 = Game.Workspace.[BUS MODEL].Light2.Light.Disabled = false
ELights3 = Game.Workspace.[BUS MODEL].Light3.Light.Disabled = false
ELights4 = Game.Workspace.[BUS MODEL].Light4.Light.Disabled = false
DLights1 = Game.Workspace.[BUS MODEL].Light1.Light.Disabled = true
DLights2 = Game.Workspace.[BUS MODEL].Light2.Light.Disabled = true
DLights3 = Game.Workspace.[BUS MODEL].Light3.Light.Disabled = true
DLights4 = Game.Workspace.[BUS MODEL].Light4.Light.Disabled = true

debounce=false

function onClick(mouse)
if not debounce then
debounce=true
i=150 --change this to the specified time in seconds
repeat wait(0.4)
ELights1
ELights2
wait(0.3)
DLights1
DLights2
ELights3
ELights4
wait(0.3)
DLights3
DLights4
until i==0
debounce=false
end

end
script.Parent.MouseButton1Click:connect(onClick)

I added a debounce so you can't activate during activation.

If I helped, hit that accept button!

1 comment

0

Thank you very much, my good friend!

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