Script does not change value on 1 part, but does on another part while being the exact same

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
2 Likes

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.

2 Likes

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

PS: Get out of here ChatGPT.


PPS: Grüzli aus Berlin.

1 Like

Already did that, everythings good, the Luft1 Value and the FirstGroup, I have no clue whats going on

1 Like

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

Grüßen aus Kreis Kleve

2 Likes

I think I know what’s going on, ill reach back to you, one sec.

2 Likes

Fixed it, everything was fine, no grammar mistakes, but the part I said was the “Working piece”, was overriding the piece that I wanted it to do.

2 Likes

Thank you for your attempt though,

Here’s the as good as finished result!

External Media
2 Likes

Looks really cool! Glad to know you figured it out

bruv I don’t use ChatGPT :skull: was just trying to be helpful…

2 Likes