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

how do i make this a loop without the script dying and doing nothing?

so what i have tried to do is to make the lights loop blink when the value is over 100 and deactivate later, im only good at modeling so this is a nightmare

local lights = script.Parent.Model.LEDIN.LEDS:GetChildren()
workspace.TEMP.Changed:Connect(function()
  if workspace.TEMP.Value > 100  then
    while wait() do
    for _,child in pairs(lights) do
    BrickColor.new("Institutional white") 
    Material = Enum.Material.Neon
    wait(1)    
        BrickColor.new("Dark grey") 
    Material = Enum.Material.SmoothPlastic
    wait(1)
end
end
end

2 answers

✓ Accepted answer

Hey. Just one thing, don't create a new loop every time the value changes or its gonna result in chaos.

local lights = script.Parent.Model.LEDIN.LEDS:GetChildren()
local tempvalue = 0
workspace.TEMP.Changed:Connect(function(value)
	tempvalue = value -- value that holds the "TEMP" value so you can use it for later
end)

spawn(function() -- spawn allows for the code to run in serial, this way, you can write more code under
	while wait() do
		if tempvalue <= 100 then continue end -- moves onto next iteration if tempvalue is less than or equal to 100
		for _,child in pairs(lights) do
			spawn(function() -- serial again, so every led blinks at the same time, or if thats not the effect you're going for
				child.Color = BrickColor.new("Institutional white") 
				child.Material = Enum.Material.Neon
				wait(1)    
				child.Color = BrickColor.new("Dark grey") 
				child.Material = Enum.Material.SmoothPlastic
				wait(1)
			end)
		end
	end
end)

4 comments

0

thank you, ill close the topic if this works!

0

problem is that it only flashes once then stops so idk whats happening, i also changed value to workspace.TEMP.value if thats the correct way to do it

0

then that means the tempvalue is under 100

0

oh i see, also it flashes way too quickly so im going to see whats happening

You can make a variable change every time the lights blink and use repeat wait() until variable == Number for the light blinking system. while wait() do makes it so that they blink until the server shuts down.

-Ducky

Developer

Youtuber

1 comment

0

wdym? i get a end error at line 3 if i made it a repeat

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