Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script does not detect negative Integers?

I have a script that returns a special string whenever an Integer is negative, but it does not change and instead returns the negative number.

Code :

Label = script.Parent
Kin = game.Players.LocalPlayer.Statistics.Values.Kin

while wait(.25) do
	if Kin.Value < 1000 then
		Label.Text = Kin.Value
	elseif Kin.Value < 1000000 and Kin.Value > 999 then
		length = string.len(tostring(Kin.Value))
		Label.Text = string.sub(tostring(Kin.Value), 1, length - 3) .. "," .. string.sub(tostring(Kin.Value), length - 2)
	elseif Kin.Value < 10000000 and Kin.Value > 999999 then
		length = string.len(tostring(Kin.Value))
		Label.Text = string.sub(tostring(Kin.Value), 1, length - 6) .. "," .. string.sub(tostring(Kin.Value), length - 5, length - 3) .. "," .. string.sub(tostring(Kin.Value), length - 2)
	elseif Kin.Value > 9999999 then
		Label.Text = "E-KL-OF"
	elseif Kin.Value < 0 then
		Label.Text = "E-KL-UF"
	end
end

The part I am talking about is at Line 17 and 18. Every variable is correctly defined. Whenever I change the value of Kin to a negative number (e.g. -15), the Label's Text displays the same number (-15 in this case) instead of the message "E-KL-UF". Any help?

The output gives no errors.

2 answers

✓ Accepted answer

Anything less than 0 is also less than 1000, meaning that it is getting caught in the first condition. Make sure that your conditions are exclusive, and not subsets.

The solution is to simply move the 0 condition to before the 1000 condition

1 comment

0

Thank you, did not see I missed that.

Negative numbers will pass the first condition.

There's no point in you testing the low ends of the elseif because you've already reached the else part.

The best way to organize it like this is this:

if value < 0 then

elseif value < 1000 then

elseif value < 10000 then

elseif value < 100000 then

else

end

It's much easier to understand and much much clearer.

This discussion is preserved as it was. New answers, comments, and votes are closed.