Attempt to call a nil value

  1. What do you want to achieve?

Simple! i saw a topic post about a Number Abbreviation System (Number Abbreviation System)
And with that to set my gui text value with it.

  1. What is the issue?

The problem is that i can not find what is wrong my script and why its giving the output.
The problem seems to appear when calling out the function

  1. What solutions have you tried so far?

Everything. I know that the error means that the value has no object or data to it and i cant seem to find why

CODE:

local player = game.Players.LocalPlayer

while wait(.25) do
	local status = player:WaitForChild("Stats")
	local Sender = status.Cash.Value
	local n = Sender
	abbreviateNumber(n)
	wait()
	local NumberToSet = abbreviateNumber()
	script.Parent.Text = NumberToSet
end

function abbreviateNumber (n)
	local s = tostring(math.floor(n))
	return string.sub(s, 1, ((#s - 1) % 3) + 1) .. ({"", "K", "M", "B", "T", "QA", "QI", "SX", "SP", "OC", "NO", "DC", "UD", "DD", "TD", "QAD", "QID", "SXD", "SPD", "OCD", "NOD", "VG", "UVG"})[math.floor((#s - 1) / 3) + 1]
end

Thanks and have a good one!

reverse the function and the while loop like this, maybe it doesnt know what the function is yet since its going in order

local player = game.Players.LocalPlayer

function abbreviateNumber (n)
	local s = tostring(math.floor(n))
	return string.sub(s, 1, ((#s - 1) % 3) + 1) .. ({"", "K", "M", "B", "T", "QA", "QI", "SX", "SP", "OC", "NO", "DC", "UD", "DD", "TD", "QAD", "QID", "SXD", "SPD", "OCD", "NOD", "VG", "UVG"})[math.floor((#s - 1) / 3) + 1]
end

while wait(.25) do
	local status = player:WaitForChild("Stats")
	local Sender = status.Cash.Value
	local n = Sender
	abbreviateNumber(n)
	wait()
	local NumberToSet = abbreviateNumber()
	script.Parent.Text = NumberToSet
end

Worked, well semi. now its giving the error:
invalid argument #1 to ‘floor’ (number expected, got nil)

ah, change your status variable name to statusval or something, something else, its highlighted blue

Will try. In studio its not so thats quite weird

Yep, still the same outcome as before

oh okay, im on mobile, i think i see it now, ur trying to run the function twice, one first and one later, try this

local player = game.Players.LocalPlayer

function abbreviateNumber (n)
	local s = tostring(math.floor(n))
	return string.sub(s, 1, ((#s - 1) % 3) + 1) .. ({"", "K", "M", "B", "T", "QA", "QI", "SX", "SP", "OC", "NO", "DC", "UD", "DD", "TD", "QAD", "QID", "SXD", "SPD", "OCD", "NOD", "VG", "UVG"})[math.floor((#s - 1) / 3) + 1]
end

while wait(.25) do
	local status = player:WaitForChild("Stats")
	local Sender = status.Cash.Value
	local n = Sender
	wait()
	local NumberToSet = abbreviateNumber(n)
	script.Parent.Text = NumberToSet
end
1 Like

Omg works!. Thank you so much you dont know how much it means to me

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