Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
tantec 305 Moderation Voter
4 years ago

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)
0
thank you, ill close the topic if this works! Ainxcus 2 — 4y
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 Ainxcus 2 — 4y
0
then that means the tempvalue is under 100 tantec 305 — 4y
0
oh i see, also it flashes way too quickly so im going to see whats happening Ainxcus 2 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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

0
wdym? i get a end error at line 3 if i made it a repeat Ainxcus 2 — 4y

Answer this question