Help me with this

I’m making a reactor cooling fan system where the fans stop cooling the core during the startup, after the startup and set the fan speed, this happened.

The video:

The script:

local TopMegafan = game.Workspace.Reactor.MegaFanTop
local BottomMegaFan = game.Workspace.Reactor.MegaFanBottom
local TempChanger = game.ReplicatedStorage.ReactorSystems.TempChanger
local Rise = game.ReplicatedStorage.ReactorSystems.Rise
local Offline = game.ReplicatedStorage.ReactorSystems.Offline
local Generate = game.ReplicatedStorage.ReactorSystems.Generate

while task.wait() do
	if TopMegafan.Speed.Value == 0.05 and BottomMegaFan.Speed.Value == 0 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 1
	elseif TopMegafan.Speed.Value == 0.05 and BottomMegaFan.Speed.Value == 0 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0 and BottomMegaFan.Speed.Value == 0.05 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 1
	elseif TopMegafan.Speed.Value == 0 and BottomMegaFan.Speed.Value == 0.05 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.05 and BottomMegaFan.Speed.Value == 0.05 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 2
	elseif TopMegafan.Speed.Value == 0.05 and BottomMegaFan.Speed.Value == 0.05 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.1 and BottomMegaFan.Speed.Value == 0 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 2
	elseif TopMegafan.Speed.Value == 0.1 and BottomMegaFan.Speed.Value == 0 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0 and BottomMegaFan.Speed.Value == 0.1 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 2
	elseif TopMegafan.Speed.Value == 0 and BottomMegaFan.Speed.Value == 0.1 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.1 and BottomMegaFan.Speed.Value == 0.1 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 4
	elseif TopMegafan.Speed.Value == 0.1 and BottomMegaFan.Speed.Value == 0.1 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.15 and BottomMegaFan.Speed.Value == 0 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 3
	elseif TopMegafan.Speed.Value == 0.15 and BottomMegaFan.Speed.Value == 0 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0 and BottomMegaFan.Speed.Value == 0.15 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 3
	elseif TopMegafan.Speed.Value == 0 and BottomMegaFan.Speed.Value == 0.15 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.15 and BottomMegaFan.Speed.Value == 0.15 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 6
	elseif TopMegafan.Speed.Value == 0.15 and BottomMegaFan.Speed.Value == 0.15 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.2 and BottomMegaFan.Speed.Value == 0 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 4
	elseif TopMegafan.Speed.Value == 0.2 and BottomMegaFan.Speed.Value == 0 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0 and BottomMegaFan.Speed.Value == 0.2 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 4
	elseif TopMegafan.Speed.Value == 0 and BottomMegaFan.Speed.Value == 0.2 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.2 and BottomMegaFan.Speed.Value == 0.2 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 8
	elseif TopMegafan.Speed.Value == 0.2 and BottomMegaFan.Speed.Value == 0.2 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.25 and BottomMegaFan.Speed.Value == 0 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 5
	elseif TopMegafan.Speed.Value == 0.25 and BottomMegaFan.Speed.Value == 0 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0 and BottomMegaFan.Speed.Value == 0.25 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 5
	elseif TopMegafan.Speed.Value == 0 and BottomMegaFan.Speed.Value == 0.25 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.25 and BottomMegaFan.Speed.Value == 0.25 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 10
	elseif TopMegafan.Speed.Value == 0.25 and BottomMegaFan.Speed.Value == 0.25 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.2 and BottomMegaFan.Speed.Value == 0.25 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 9
	elseif TopMegafan.Speed.Value == 0.2 and BottomMegaFan.Speed.Value == 0.25 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.25 and BottomMegaFan.Speed.Value == 0.2 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 9
	elseif TopMegafan.Speed.Value == 0.25 and BottomMegaFan.Speed.Value == 0.2 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.15 and BottomMegaFan.Speed.Value == 0.25 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 8
	elseif TopMegafan.Speed.Value == 0.15 and BottomMegaFan.Speed.Value == 0.25 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.25 and BottomMegaFan.Speed.Value == 0.15 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 8
	elseif TopMegafan.Speed.Value == 0.25 and BottomMegaFan.Speed.Value == 0.15 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.1 and BottomMegaFan.Speed.Value == 0.25 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 7
	elseif TopMegafan.Speed.Value == 0.1 and BottomMegaFan.Speed.Value == 0.25 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.25 and BottomMegaFan.Speed.Value == 0.1 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 7
	elseif TopMegafan.Speed.Value == 0.25 and BottomMegaFan.Speed.Value == 0.1 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.05 and BottomMegaFan.Speed.Value == 0.25 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 6
	elseif TopMegafan.Speed.Value == 0.05 and BottomMegaFan.Speed.Value == 0.25 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.25 and BottomMegaFan.Speed.Value == 0.05 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 6
	elseif TopMegafan.Speed.Value == 0.25 and BottomMegaFan.Speed.Value == 0.05 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.15 and BottomMegaFan.Speed.Value == 0.2 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 7
	elseif TopMegafan.Speed.Value == 0.15 and BottomMegaFan.Speed.Value == 0.2 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.2 and BottomMegaFan.Speed.Value == 0.15 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 7
	elseif TopMegafan.Speed.Value == 0.2 and BottomMegaFan.Speed.Value == 0.15 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.1 and BottomMegaFan.Speed.Value == 0.2 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 6
	elseif TopMegafan.Speed.Value == 0.1 and BottomMegaFan.Speed.Value == 0.2 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.2 and BottomMegaFan.Speed.Value == 0.1 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 6
	elseif TopMegafan.Speed.Value == 0.2 and BottomMegaFan.Speed.Value == 0.1 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.05 and BottomMegaFan.Speed.Value == 0.2 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 5
	elseif TopMegafan.Speed.Value == 0.05 and BottomMegaFan.Speed.Value == 0.2 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.2 and BottomMegaFan.Speed.Value == 0.05 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 5
	elseif TopMegafan.Speed.Value == 0.2 and BottomMegaFan.Speed.Value == 0.05 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.15 and BottomMegaFan.Speed.Value == 0.1 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 5
	elseif TopMegafan.Speed.Value == 0.15 and BottomMegaFan.Speed.Value == 0.1 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.1 and BottomMegaFan.Speed.Value == 0.15 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 5
	elseif TopMegafan.Speed.Value == 0.1 and BottomMegaFan.Speed.Value == 0.15 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.05 and BottomMegaFan.Speed.Value == 0.15 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 4
	elseif TopMegafan.Speed.Value == 0.05 and BottomMegaFan.Speed.Value == 0.15 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.15 and BottomMegaFan.Speed.Value == 0.05 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 4
	elseif TopMegafan.Speed.Value == 0.15 and BottomMegaFan.Speed.Value == 0.05 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.05 and BottomMegaFan.Speed.Value == 0.1 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 3
	elseif TopMegafan.Speed.Value == 0.05 and BottomMegaFan.Speed.Value == 0.1 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0.1 and BottomMegaFan.Speed.Value == 0.05 and Offline.Value == false and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 3
	elseif TopMegafan.Speed.Value == 0.1 and BottomMegaFan.Speed.Value == 0.05 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0 or TopMegafan.Speed.Value > 0 and BottomMegaFan.Speed.Value == 0 or BottomMegaFan.Speed.Value > 0 and Offline.Value == false and Generate.Value == true then
		Rise.Value = true
		TempChanger.Value = 100
	elseif TopMegafan.Speed.Value == 0 or TopMegafan.Speed.Value > 0 and BottomMegaFan.Speed.Value == 0 or BottomMegaFan.Speed.Value > 0 and Offline.Value == true and Generate.Value == true then
		Rise.Value = false
		TempChanger.Value = 0
	end
	if TopMegafan.Speed.Value == 0 and BottomMegaFan.Speed.Value == 0 and Offline.Value == false and Generate.Value == false then
		Rise.Value = true
		TempChanger.Value = 6
	elseif TopMegafan.Speed.Value == 0 and BottomMegaFan.Speed.Value == 0 and Offline.Value == true and Generate.Value == false then
		Rise.Value = false
		TempChanger.Value = 0
	end
end

Any help is appreciated, thanks.

3 Likes

No offence bro, but u srsly can’t expect people to go through that doo-doo you call a script. Try to refactor the script using an extremely useful feature called tables. I wud have helped you myself but I’m down with a headache so you are on your own.

1 Like

I watched the video like 3 times and I can’t figure out what’s wrong with it, could you provide more information?
Also it’s never good to have that many if statements in a script, as it will cause a lot of performance issues for other scripts and FPS.
The script has to check EACH if statement, EACH ONE OF THEM. Even if it returns false, every time that code runs the script goes through all the if statements.

I recommend rewriting the script and instead of checking values like that you could try using the function Object:GetPropertyChangedValue("Value") which is an event that, well, fires when the property Value of Object changes.
Find any way to refrain from using so many if statements

You see the Rising by 100K after the startup? It’s the issue, I want it to stop cooling during startup and resume cooling after the startup, find the line that has Generate == true.

As I’ve mentioned above, that script is not the way to go about this. It’s not optimal at all and it’s hard to look at.

As previously mentioned, that script is rather poorly-written which only makes it harder to go through and find / fix bugs. I would recommend rewriting it and using simple math to calculate what the value of temp should be based on fan speeds. I would also recommend checking the Offline and Generate values in your main if-statement of the rewritten script.

In the future, if looking for help, I would also recommend being more specific and not telling someone to go find a certain line when you have a script that’s hard to read like that.

If not already answered by the time I am able to get on PC, I’ll see if I can assist further. Hope this helped a bit. :slight_smile:

local MegaFanTop = game.Workspace.Reactor.MegaFanTop
local MegaFanBottom = game.Workspace.Reactor.MegaFanBottom
local Generate = game.ReplicatedStorage.ReactorSystems.Generate
local Rise = game.ReplicatedStorage.ReactorSystems.Rise
local TempChanger = game.ReplicatedStorage.ReactorSystems.TempChanger
local Offline = game.ReplicatedStorage.ReactorSystems.Offline

MegaFanTop.Speed:GetPropertyChangedSignal("Value"):Connect(function()
	if MegaFanTop.Speed.Value == 0.05 and Generate.Value == false and Offline.Value == false then
		Rise.Value = false
		TempChanger.Value = 2
	end
	if MegaFanTop.Speed.Value == 0.1 and Generate.Value == false and Offline.Value == false then
		Rise.Value = false
		TempChanger.Value = 4
	end
	if MegaFanTop.Speed.Value == 0.15 and Generate.Value == false and Offline.Value == false then
		Rise.Value = false
		TempChanger.Value = 6
	end
	if MegaFanTop.Speed.Value == 0.2 and Generate.Value == false and Offline.Value == false then
		Rise.Value = false
		TempChanger.Value = 8
	end
	if MegaFanTop.Speed.Value == 0.25 and Generate.Value == false and Offline.Value == false then
		Rise.Value = false
		TempChanger.Value = 10
	end
	if MegaFanTop.Speed.Value == 0 and Generate.Value == false and Offline.Value == false then
		Rise.Value = true
		TempChanger.Value = 6
	end
end)

MegaFanBottom.Speed:GetPropertyChangedSignal("Value"):Connect(function()
	if MegaFanBottom.Speed.Value == 0.05 and Generate.Value == false and Offline.Value == false then
		Rise.Value = false
		TempChanger.Value = 2
	end
	if MegaFanBottom.Speed.Value == 0.1 and Generate.Value == false and Offline.Value == false then
		Rise.Value = false
		TempChanger.Value = 4
	end
	if MegaFanBottom.Speed.Value == 0.15 and Generate.Value == false and Offline.Value == false then
		Rise.Value = false
		TempChanger.Value = 6
	end
	if MegaFanBottom.Speed.Value == 0.2 and Generate.Value == false and Offline.Value == false then
		Rise.Value = false
		TempChanger.Value = 8
	end
	if MegaFanBottom.Speed.Value == 0.25 and Generate.Value == false and Offline.Value == false then
		Rise.Value = false
		TempChanger.Value = 10
	end
	if MegaFanBottom.Speed.Value == 0 and Generate.Value == false and Offline.Value == false then
		Rise.Value = false
		TempChanger.Value = 6
	end
end)

Offline:GetPropertyChangedSignal("Value"):Connect(function()
	if MegaFanTop.Speed.Value >= 0 or MegaFanBottom.Speed.Value >= 0 and Generate.Value == false and Offline.Value == true then
		Rise.Value = true
		TempChanger.Value = 0
	end
end)

Generate:GetPropertyChangedSignal("Value"):Connect(function()
	if MegaFanTop.Speed.Value >= 0 or MegaFanBottom.Speed.Value >= 0 and Generate.Value == true and Offline.Value == false then
		Rise.Value = true
		TempChanger.Value = 100
	end
end)

You could condense your script even more by doing this;

local MegaFanTop = game.Workspace.Reactor.MegaFanTop
local MegaFanBottom = game.Workspace.Reactor.MegaFanBottom
local Generate = game.ReplicatedStorage.ReactorSystems.Generate
local Rise = game.ReplicatedStorage.ReactorSystems.Rise
local TempChanger = game.ReplicatedStorage.ReactorSystems.TempChanger
local Offline = game.ReplicatedStorage.ReactorSystems.Offline

MegaFanTop.Speed:GetPropertyChangedSignal("Value"):Connect(function()
	if not Generate.Value and not Offline.Value then
		local FanSpeed = MegaFanTop.Speed.Value
		local Temp = 6
		
		if FanSpeed ~= 0 then
			Temp = FanSpeed*40
			Rise.Value = false
		else
			Rise.Value = true
		end
		
		TempChanger.Value = Temp
	end
end)

MegaFanBottom.Speed:GetPropertyChangedSignal("Value"):Connect(function()
	if not Generate.Value and not Offline.Value then
		local FanSpeed = MegaFanBottom.Speed.Value
		local Temp = 6

		if FanSpeed ~= 0 then
			Temp = FanSpeed*40
			Rise.Value = false
		else
			Rise.Value = true
		end

		TempChanger.Value = Temp
	end
end)

Offline:GetPropertyChangedSignal("Value"):Connect(function()
	if not Offline.Value then return end -- Since we need this value to be true, we skip the rest of the code if not true
	if MegaFanTop.Speed.Value >= 0 or MegaFanBottom.Speed.Value >= 0 and not Generate.Value then
		Rise.Value = true
		TempChanger.Value = 0
	end
end)

Generate:GetPropertyChangedSignal("Value"):Connect(function()
	if not Generate.Value then return end -- Since we need this value to be true, we skip the rest of the code if not true
	if MegaFanTop.Speed.Value >= 0 or MegaFanBottom.Speed.Value >= 0 and not Offline.Value then
		Rise.Value = true
		TempChanger.Value = 100
	end
end)
1 Like

That doesn’t fix anything, the temperature system doesn’t go up by 6, it just goes by 100 even I set the megafan levels to 5, this happened after the startup.