Cannot change multiple part properties at the same time

Hey there. I am unable to change this lights properties via script. I am doing it with multiple lights.
There are no errors.

local Parts = {
			-- Things are in here.
		}


game.ReplicatedStorage.CodeRed.OnServerEvent:Connect(function(plr)
	if plr:GetRankInGroup() == 56 then
		
		script.Alarm.Value = true
		
		for i, Part in pairs(Parts) do
			
			while script.Alarm.Value == true do
				Part.Enabled = true
				Part.Brightness = 2
				wait(0.7)
				Part.Brightness = 0.5
				print("went through")
			end
			
		end
	end
end)

Any help?

Thanks.

1 Like

You never break the while loop so it never gets the chance to loop for the other parts. Maybe try spawn()

edit: or just change the while loop to an if statement.

1 Like

Can’t you just coroutine it?

local Parts = {
			-- Things are in here.
		}


game.ReplicatedStorage.CodeRed.OnServerEvent:Connect(function(plr)
	if plr:GetRankInGroup() == 56 then
		
		script.Alarm.Value = true
		
		for i, Part in pairs(Parts) do
			coroutine.resume(coroutine.create(function()
			    while script.Alarm.Value == true do
				    Part.Enabled = true
				    Part.Brightness = 2
				    wait(0.7)
				    Part.Brightness = 0.5
				    print("went through")
			    end
		    end))
		end
	end
end)
1 Like

I am sorry, but that will not help.

Is there a reason it’s in a while loop?

It is in a while loop because the alarm is going to keep going until the alarm value is false.

Ok then how exactly would the coroutine not work?

1 Like

It goes very fast and lags the server. And still the lights wont change brightness.

1 Like

Try this code layout:

function toggleLights(state)

end

while value == true do
  toggleLights(true)
  wait(.7)
  toggleLights(false)
  wait(.7)
end
2 Likes

Oop-
I’m so dumb lol. Should have though of that.

1 Like

Oh, so the brightness isn’t changing?

1 Like

Yes, still after @metatablecatmaid 's comment.

Is the Part variable actually a part or a light or smt?

1 Like

The part variable is right now a light.

Is it printing “went through” like it’s supposed to?

1 Like

Yes, it is printing went through. No errors at all.

Exactly what instance is the Part variable?

The instance of the part is a light.

Pointlight to be more specific.

1 Like

Does the light turn on at all?

1 Like

Yes. It is on when the game loads.