I’m making a ventilation system, and a switch that has 2 positions, Low (Value = 1) and Full/High (Value = 2)
There’s also an Unlock value that needs to be true (To Unlock the ventilation group)
The script checks that if its unlocked AND if the value is 1 and then sets the RPM value to 10
Theres the exact same piece of code that sets the RPM to 15 when the value of the switch is 2.
Here’s the code, I already checked typos and all other combinations I am really really confused
–broken piece
if Values:WaitForChild("Luft1").Value == 1 and FirstGroupOn == true then
Luft1SlowIndicator.Color = YellowOn.Value
Luft1SlowIndicator.Material = Enum.Material.Neon
RS.Ventilation:WaitForChild("Group1RPM").Value = 10
else
Luft1SlowIndicator.Color = YellowOff.Value
Luft1SlowIndicator.Material = Enum.Material.SmoothPlastic
RS.Ventilation:WaitForChild("Group1RPM").Value = 0
end
–working piece
if Values:WaitForChild("Luft1").Value == 2 and FirstGroupOn == true then
Luft1FullIndicator.Color = GreenOn.Value
Luft1FullIndicator.Material = Enum.Material.Neon
RS.Ventilation:WaitForChild("Group1RPM").Value = 15
else
Luft1FullIndicator.Color = GreenOff.Value
Luft1FullIndicator.Material = Enum.Material.SmoothPlastic
RS.Ventilation:WaitForChild("Group1RPM").Value = 0
end
It may help to put debug print statements to check if the code even reaches the point where it’s supposed to change the value.
if Values:WaitForChild("Luft1").Value == 1 and FirstGroupOn == true then
Luft1SlowIndicator.Color = YellowOn.Value
Luft1SlowIndicator.Material = Enum.Material.Neon
print("reached point 1")
RS.Ventilation:WaitForChild("Group1RPM").Value = 10
else
Luft1SlowIndicator.Color = YellowOff.Value
Luft1SlowIndicator.Material = Enum.Material.SmoothPlastic
print("reached point 2")
RS.Ventilation:WaitForChild("Group1RPM").Value = 0
end
Run the thing and see what happens when you are turning the switch. If those statements don’t print/the one you expected to print doesn’t, then the issue is in the condition given to the if statement.
It would seem to me that the problem is not the provided code, but the one you’re using to call it.
local LOW = 1
local HIGH = 2
if FirstGroupOn then
local luft1_state = Values:WaitForChild("Luft1").Value
local group1rpm = RS.Ventilation:WaitForChild("Group1RPM")
if luft1_state == LOW then
Luft1SlowIndicator.Color = YellowOn.Value
Luft1SlowIndicator.Material = Enum.Material.Neon
group1rpm.Value = 10
elseif luft1_state == HIGH then
Luft1FullIndicator.Color = GreenOn.Value
Luft1FullIndicator.Material = Enum.Material.Neon
group1rpm.Value = 15
else
Luft1FullIndicator.Color = GreenOff.Value
Luft1FullIndicator.Material = Enum.Material.SmoothPlastic
group1rpm.Value = 0
end
end
It does turn on the “Yellow” light when the conditions are right, the only problem is that the RPM Value is not changing, and when I change it by hand it automatically goes back to 0