I am having issues with if statements with negative and positive values

So basically i am having absolutely unacceptable issues with if statements that just doesn’t work as expected

For example:
if the number that is getting passed into my code is positive like 950 its gonna return the correct result
BUT
if the number is negative like -2000 its gonna return NIL.

if someone could help me i would appreciate it i just cannot figure out the issue(s)

local module = {}

function module:Get()
	local result = nil
	local coreTemp = game.ReplicatedStorage.CoreTemp.Value

	if coreTemp <= -4000 then
		result = "FREEZEDOWN"
	elseif coreTemp < -2000 then
		result = "TOO COLD"
	elseif coreTemp >= -1999 and coreTemp <= 949 then
		result = "NORMAL"
	elseif coreTemp >= 950 and coreTemp <= 2600 then
		result = "CRITICAL"
	elseif coreTemp >= 2600 and coreTemp <= 3999 then
		result = "OVERHEAT"
	elseif coreTemp >= 4000 then
		result = "MELTDOWN"
	end

	return result
end

return module

1 Like

Srry, but i still dont understand what is your problem?

Is the module script doesnt work or what?

usually i’ll type the function like this

function module.Get()

so i can require the module script other module

local moduleScript = require(--The position of module script)

modulescript.Get()

and you can get the return like this

local moduleScript = require(--The position of module script)

local temp = modulescript.Get() --temp variable will save return value of the module script
print(temp) -- its should print the temperature status

You are checking if temp is lower than -2000 instead of lower or equal, this makes it so if temp is exactly -2000 all if statements fail.

if its a . or : doesnt affect if the script is gonna run the two dots just doesnt have autocompletion but yeah basically the module returns the correct status only if the temp is positive even if it checks for negativity

2 Likes

owh yeah i didn’t notice that, thanks

1 Like

thanks for the new knowledge I just found out that functions can be written like that

1 Like

well even if its like that “elseif coreTemp <=-2000 then” it doesnt work

1 Like

Are you sure CoreTemp is being set correctly? Try printing it before the if statement.

1 Like

yeah there is no problem at all in the script, i already try it in my roblox studio

1 Like

i myself putted it in runtime to the values i wanted to test and yes it just dont work

1 Like

module part:
image

server script part:
image

for all of them but toocold it work

Result you are returning is "TOO COLD" while you are checking for "TOOCOLD".

1 Like

bro how did i didnt notice that :sob:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.