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

I made script with the function that I want to go loop. How do I do this?

I'm learning at scripting and I made function that I want to loop but how do I do this? I added while true do then the script ended up not working. What should I do?

local light = game.Workspace.Lights

function onClicked()
	light.Sound:Play()
	light.Red.Material = "Neon"
	light.Blue.Material = "Plastic"
	light.Red.PointLight.Enabled = true
	light.Blue.PointLight.Enabled = false
    wait(0.5)
	light.Blue.Material = "Neon"
	light.Red.Material = "Plastic"
	light.Red.PointLight.Enabled = false
	light.Blue.PointLight.Enabled = true
end



script.Parent.TextButton.MouseButton1Down:connect(onClicked)

Basically I want the function to loop when you click the GUI that I made.

2 comments

0

I know how to loop a script but not with functions

0

Basically I want the script to loop when you press the button

1 answer

✓ Accepted answer

local light = game.Workspace.Lights

function onClicked()
	while true do
	    light.Sound:Play()
	    light.Red.Material = "Neon"
	    light.Blue.Material = "Plastic"
	    light.Red.PointLight.Enabled = true
	    light.Blue.PointLight.Enabled = false
	    wait(0.5)
	    light.Blue.Material = "Neon"
	    light.Red.Material = "Plastic"
	    light.Red.PointLight.Enabled = false
	    light.Blue.PointLight.Enabled = true
	end
end

script.Parent.TextButton.MouseButton1Down:connect(onClicked)


if you want make a loop just add while true do.

ps: While true do can break you game , use a wait() on ALL LOOP SCRIPTS for dont break it.

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