use math.clamp(number x , number min , number max )
local Temperature = game.ReplicatedStorage.ReactorSystems.Temperature
local Offline = game.ReplicatedStorage.ReactorSystems.Offline
local MaxTemp = game.ReplicatedStorage.ReactorSystems.MaxTemp
local function temperature_rise()
Temperature.Value = math.floor(Temperature.Value) + 50
end
while task.wait(1) do
temperature_rise()
Temperature.Value = math.clamp(Temperature.Value, 0, 5000)
end
local Temperature = game.ReplicatedStorage.ReactorSystems.Temperature
local Offline = game.ReplicatedStorage.ReactorSystems.Offline
local MaxTemp = game.ReplicatedStorage.ReactorSystems.MaxTemp
local function temperature_rise()
Temperature.Value = math.floor(Temperature.Value) + 50
end
while task.wait(1) do
temperature_rise()
Temperature.Value = math.clamp(Temperature.Value, 0, 5000)
if Temperature.Value == 0 or Temperature.Value == 5000 then
break
end
end
In my code, I added a “Rise” variable to show if it’s going to rise or not.
local Temperature = game.ReplicatedStorage.ReactorSystems.Temperature
local Offline = game.ReplicatedStorage.ReactorSystems.Offline
local MaxTemp = game.ReplicatedStorage.ReactorSystems.MaxTemp
local Rise = true
local function temperature_rise()
Temperature.Value = math.floor(Temperature.Value) + 50
end
local function temperature_decrease()
Temperature.Value = math.floor(Temperature.Value) - 50
end
while task.wait(1) do
if Rise == true then
temperature_rise()
else
temperature_decrease()
end
Temperature.Value = math.clamp(Temperature.Value, 0, 5000)
if Temperature.Value == 0 or Temperature.Value == 5000 then
break
end
end
From what I understood, the TempChanger value shows if it’s going to rise or not.
Change
local Rise = true
to
local Rise = game.ReplicatedStorage.ReactorSystems.TempChanger
and change the if statement to
if Rise.Value == true then
FINAL RESULT
local Temperature = game.ReplicatedStorage.ReactorSystems.Temperature
local Offline = game.ReplicatedStorage.ReactorSystems.Offline
local MaxTemp = game.ReplicatedStorage.ReactorSystems.MaxTemp
local Rise = game.ReplicatedStorage.ReactorSystems.TempChanger
local function temperature_rise()
Temperature.Value = math.floor(Temperature.Value) + 50
end
local function temperature_decrease()
Temperature.Value = math.floor(Temperature.Value) - 50
end
while task.wait(1) do
if Rise.Value == true then
temperature_rise()
else
temperature_decrease()
end
Temperature.Value = math.clamp(Temperature.Value, 0, 5000)
if Temperature.Value == 0 or Temperature.Value == 5000 then
break
end
end
local Temperature = game.ReplicatedStorage.ReactorSystems.Temperature
local Offline = game.ReplicatedStorage.ReactorSystems.Offline
local MaxTemp = game.ReplicatedStorage.ReactorSystems.MaxTemp
local Rise = true
local TempChanger = game.ReplicatedStorage.ReactorSystems.TempChanger
local function temperature_rise()
Temperature.Value = math.floor(Temperature.Value) + TempChanger.Value
end
local function temperature_decrease()
Temperature.Value = math.floor(Temperature.Value) - TempChanger.Value
end
while task.wait(1) do
if Rise == true then
temperature_rise()
else
temperature_decrease()
end
Temperature.Value = math.clamp(Temperature.Value, 0, 5000)
if Temperature.Value == 0 or Temperature.Value == 5000 then
break
end
end
I didn’t really understand what you mean, but if you want the loop to stop if the temperature is higher than 5000 or lower than 0 then i think this should help:
local Temperature = game.ReplicatedStorage.ReactorSystems.Temperature
local Offline = game.ReplicatedStorage.ReactorSystems.Offline
local MaxTemp = game.ReplicatedStorage.ReactorSystems.MaxTemp
local function temperature_rise()
local temp = math.floor(Temperature.Value)
Temperature.Value = math.clamp(temp + 50, 0, 5000)
end
while task.wait(1) do
If Temperature.Value > 5000 or Temperature.Value < 0 then break end
if Temperature.Value < 5000 then
temperature_rise()
end
end
local Temperature = game.ReplicatedStorage.ReactorSystems.Temperature
local Offline = game.ReplicatedStorage.ReactorSystems.Offline
local MaxTemp = game.ReplicatedStorage.ReactorSystems.MaxTemp
local Rise = game.ReplicatedStorage.ReactorSystems.Rise
local TempChanger = game.ReplicatedStorage.ReactorSystems.TempChanger
local function temperature_rise()
Temperature.Value = math.floor(Temperature.Value) + TempChanger.Value
end
local function temperature_decrease()
Temperature.Value = math.floor(Temperature.Value) - TempChanger.Value
end
while task.wait(1) do
if Rise.Value == true then
temperature_rise()
else
temperature_decrease()
end
Temperature.Value = math.clamp(Temperature.Value, 0, 5000)
if Temperature.Value == 0 or Temperature.Value == 5000 then
break
end
end