I wanted to make a temperature limit system that stops increasing or decreasing when the temperature is above 5000K or below 0K but I don’t know how.
The script:
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 = temp + 50
end
while task.wait(1) do
if Temperature.Value < 5000 then
temperature_rise()
end
end
I think you can use the “and” keyword in your “if statement”, and as well as use the MaxTemp in it, assuming that is is an IntValue or a NumberValue.
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 = temp + 50
end
while task.wait(1) do
if Temperature.Value < MaxTemp.Value and Temperature.Value > 0 then
temperature_rise()
end
end
why not use math.clamp?
unless im not getting something it should work in your favor
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 = temp + 50
end
while task.wait(1) do
if Temperature.Value <= 5000 or Temperature.Value >= 0 then
temperature_rise()
end
Temperature.Value = math.clamp(Temperature.Value, Offline.Value, MaxTemp.Value)
end
unsure if offline is your minium temp but if its not just replace it with like 0 or something
Oh, I’m sorry, I thought you meant something else. Do you want the temperature to stop on a specific number, or do you want it to continue? I’m a bit confused.
I made another version of your code that has a “StartIncreasing” function and uses a for loop.
Make sure the “MaxTemp” value is set to 5000 or whatever you want it to be
When calling the function, the line after it will run when it finishes.
local Temperature = game.ReplicatedStorage.ReactorSystems.Temperature
local Offline = game.ReplicatedStorage.ReactorSystems.Offline
local MaxTemp = game.ReplicatedStorage.ReactorSystems.MaxTemp
function StartIncreasing()
for i = 1,MaxTemp.Value do
Temperature.Value = Temperature.Value + 50
task.wait(1)
end
end
StartIncreasing()
-- When the function ends, this line of code will run, so you can replace it with anything you want.
local Temperature = game.ReplicatedStorage.ReactorSystems.Temperature
local Offline = game.ReplicatedStorage.ReactorSystems.Offline
local MaxTemp = game.ReplicatedStorage.ReactorSystems.MaxTemp
function StartIncreasing()
for i = 1,MaxTemp.Value do
Temperature.Value = Temperature.Value + 50
task.wait(1)
end
end
while task.wait() do
StartIncreasing()
end
local Temperature = game.ReplicatedStorage.ReactorSystems.Temperature
local Offline = game.ReplicatedStorage.ReactorSystems.Offline
local MaxTemp = game.ReplicatedStorage.ReactorSystems.MaxTemp
while true do
task.wait(1)
local Result = Temperature.Value + 50
local canbreak = false
if Result <= 5000 then
canbreak = false
else
canbreak = true
end
if Result >= -1 then
canbreak = false
else
canbreak = true
end
if canbreak == true then
break
else
Temperature.Value = Result
end
end