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

Money script not working because of a weird error, it gives an error with booleans and numbers?

I tried to make a script what changes the money from 10000 to 10k, or from 10000000 to 10B. The script does not work how it should, and i have no idea how to fix it.

local money = script.Parent.Parent.MoneyValue
local text = script.Parent

while true do
	if money.Value < 1000 then
		text.Text = money.Value
	elseif 1000 < money.Value < 1000000 then
		text.Text = money.Value/1000 .."k"
	elseif 1000000 < money.Value < 1000000000 then
		text.Text = money.Value/1000000 .."B"
	elseif 1000000000 < money.Value < 1000000000000 then
		text.Text = money.Value/1000000000 .."T"
	elseif 1000000000000 < money.Value < 1000000000000000 then
		text.Text = money.Value/1000000000000 .."Qd"
	elseif 1000000000000000 < money.Value < 1000000000000000000 then
		text.Text = money.Value/1000000000000000 .."Qn"
	elseif 1000000000000000000 < money.Value then
		text.Text = "ERROR"
	end
	wait(0.05)
end

And if i change the MoneyValue's value to 10000 it gives the following error in the OutPut 14:12:47.097 - Players.Player1.PlayerGui.MenuGui.MoneyLabel.Script:7: attempt to compare boolean with number 14:12:47.098 - Stack Begin 14:12:47.099 - Script 'Players.Player1.PlayerGui.MenuGui.MoneyLabel.Script', Line 7 14:12:47.100 - Stack End

1 comment

0

Make sure money isn't a boolean?

1 answer

✓ Accepted answer

I believe this should fix it:

local money = script.Parent.Parent.MoneyValue
local text = script.Parent

while true do
    if money.Value < 1000 then
        text.Text = money.Value
    elseif money.Value < 1000000 then
        text.Text = money.Value/1000 .."k"
    elseif money.Value < 1000000000 then
        text.Text = money.Value/1000000 .."B"
    elseif money.Value < 1000000000000 then
        text.Text = money.Value/1000000000 .."T"
    elseif money.Value < 1000000000000000 then
        text.Text = money.Value/1000000000000 .."Qd"
    elseif money.Value < 1000000000000000000 then
        text.Text = money.Value/1000000000000000 .."Qn"
    elseif 1000000000000000000 < money.Value then
        text.Text = "ERROR"
    end
    wait(0.05)
end

The reason this happens is that in the statement if 1 < x < 2 then the 1 < x gets evaluated first, and the < operator returns a boolean value. Then, assuming x was less than 1, it would become if true < 2 then which is not valid.

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