How do I make a script wait for a value to be true until changing an object's color?

Hello Devforum,

I’m trying to make a spotlight with changeable colors, and the ability to change it while it’s off so it can be “Prepared” for the next action.

The spotlight has a what I call “Lens” part which is the part that turns Neon when it’s on, however, this part changes color even while it’s off (Since in real life, it’s the light inside a spotlight that changes color, and not really the lens). I have tried searching the devforum for help, but didn’t find success.

My goal is to have a color change instantly whenever it’s on, but for it to wait with applying the color until the light is on, when the light is off.

This is my code right now:

SystemLocals.Color.Changed:Connect(function()
	if SystemLocals.Enabled.Value == true then
		script.Parent.Color = SystemLocals.Color.Value
	else
		-- well yeah this is really how far i've gotten...
	end
end)

Any help is appreciated.

Cheers,

Herbertoes

1 Like
local value = -- path to bool value
value.Changed:Connect(function()
	repeat
		wait()
	until value.Value == true
	-- change objects color.
end)

You can simply use repeat loops.

1 Like

I am actually so disappointed I didn’t think of this, thank you very much for your help.

No problem! Glad to help you. If that solved it, please mark it as a solution to let others know.

Why are you doing value.Changed:Wait() in a value.Changed listener

1 Like

Oh sorry I posted edited it when I woke up so was quite whirly. My bad ill fix it.