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

Only work's after changed to false, for like 3 time's?

Can someone tell me why this script doesn't work when the value is changed to true, but it work's for like 3 time's after it's changed to false then stop's?

val = script.Parent.on
g1 = script.Parent.G1
g2 = script.Parent.G2

val.Changed:connect(function()
	if val.Value == true then
	repeat wait() until val.Value == false
		print("True")
		for _,v in pairs(g1:GetChildren()) do
			v.Point.Enabled = true
			v.Lighto.Enabled = true
			wait(0.02)
			v.Point.Enabled = false
			v.Lighto.Enabled = false
			wait(0.02)
		end
		for _,v in pairs(g2:GetChildren()) do
			v.Point.Enabled = true
			v.Lighto.Enabled = true
			wait(0.02)
			v.Point.Enabled = false
			v.Lighto.Enabled = false
			wait(0.02)
		end
	end
end)

1 comment

0

Have you checked why in F9?

1 answer

Line 7 is missing an indent. Also, line 7 is reason your script doesn't do anything until you set the value to false. If you want to perform lines 8+ repeatedly, you need to move the "until val.Value == false" to after line 24.

After that, it might seem to work for a few times, but I think that's just because it's only turning one light on/off at a time. That's why it's usually not a good idea to put a 'wait' command in a for loop, since your script will perform a wait for every item in your table. Instead, you should turn all the ones you want on first, then wait, then turn them off, and then wait again. You will need a total of 4 for loops for that -- 1 to turn g1 on, 1 to turn g2 on, then another 2 to turn them off after the first 'wait' command.

1 comment

0

Can you give me a example?

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