#How to make it work better

1 messages · Page 1 of 1 (latest)

granite edge
#

I want to make it so that if the temperature is more then 30 then the text is red. But if the temperature is from 25 to 29 then its orange. I made this script but i know its not gonna work that good. Anyone know how to make it work better?

#
local player = game.Players.LocalPlayer
local textlabel = player.PlayerGui.Thermodynamics.TDFrame.Frame1.AVGTemperature
local avgtemperature = game.ReplicatedStorage.AverageTemp
 
while true do
    task.wait(1)
    textlabel.AVGTemperatureValue.Text = avgtemperature.Value
    
    if avgtemperature.Value == 30 or 31 or 32 or 33 or 34 or 35 then
        textlabel.AVGTemperatureValue.TextColor = Vector3.new(235, 0, 0)
    elseif avgtemperature.Value == 20 or 21 or 22 or 23 or 24 or 25 or 26 or 27 or 28 or 29 then
        textlabel.AVGTemperatureValue.TextColor = Vector3.new(155, 62, 9)    
    end
end

versed acorn
#

You can use the < and > symbols to detect if the number is within a certain range. for example you can replace the first if statement that checks if the temperature if above 30, and do

if avgtemperature.Value >= 30 then
    --change color to red
end

in this case >= is checking if the number is equal to or greater than 30

granite edge
#

Yes but if I do >= 20 then it goes from 2O to infinity, I want it to go from 20 to 29

versed acorn
#

in this case you can just do >= 20 as an elseif statement to the if >= 30 if statement, this will automatically check the range between 20 to 29 because the first if statement is already checking if its a larger number than 30, and if its false, then it will check the elseif

#

hold up let me explain better

#

The first if statement

if num >= 30 then
#

Checks for any number above 30

#

If we add an elseif that is connected to the if statement, that condition will only be checked if the number is under 30

torpid thicket
versed acorn
granite edge
#

okay thanks!

versed acorn
#

just change the numbers to be between 20 to 29

torpid thicket
# granite edge okay thanks!

The point behind what we were saying is that if statements can have many conditions. but you can't quite compare it by doing or, because, even though english dictates that "if temperature is 30, or 31, or 32" might make sense, to a computer that's saying "if temperature is 30, or if the number 31 is true, or if the number 32 is true"

granite edge
#

oh okay thank you!