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

Attempt to perform arithmetic on nil value?

function RoundHours(playerKey) local unrHours = MinutesBank:GetAsync(playerKey) / 60; local rndHours = nil;

if(string.match(tostring(unrHours), "."))then--If it's an uneven division
	local _, lop = string.find(tostring(unrHours), ".");
	local strLen = string.len(tostring(unrHours));
	
	if(tonumber(string.sub(tostring(unrHours), lop, strLen)) >= 0.5)then--Round up
		rndHours = tonumber(string.sub(tostring(unrHours), 1, lop - 1)) + 1;--ERROR: attempt to perform arithmetic on nil value
	else--Round down
		rndHours = tonumber(string.sub(tostring(unrHours), 1, lop - 1));
	end
end

if(rndHours == nil)then
	return 0;
else
	return rndHours;
end

end

It says that there's an attempt to perform an arithmetic on a nil value, but I can't figure out where the nil value is. I commented on the line it was on. Thanks in advance!

2 comments

0

Why arithmetic on a nil value?

0

Not sure what you mean by that, I just don't know where the nil value is on line 6.

1 answer

It is impossible to perform arithmetic on a nil value; Lua won't let you do that. You can only perform arithmetic on a variable with actual data in it, not a nil value.

3 comments

0

I really don't see why you're trying to do arithmetic on something that is nil. That's really dumb.

0

Dont hurt peoples dre-e-e-e-eams!!!!!!!!

0

clrik, I wouldn't talk if I were you. You incorrectly modified the CFrame script of mine (mine WAS correct; if you try the one you gave me, the part goes nuts), so leave this to me. I'm not even sure if you even know how to script correctly. I question your abilities to answer questions such as this one.

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