Attempt to index a nil value

so i made a script which gives me the error from the title.
here is the script: the error line is line 7
it is not possible that cash doesnt exist since the function fired (if cash didnt exist the function wouldnt fire) and its value is not nil so i dont know whats wrong

local plr = game.Players.LocalPlayer
local cash = plr:WaitForChild("leaderstats"):WaitForChild("Cash")
cash.Changed:Connect(function()
	if cash.Value < 1000 then
		script.Parent.Amount.Text = cash.Value
	elseif cash.Value >= 1000 then
		local aftercoma = math.floor((cash.Value-math.Floor(cash.Value))+0.5)
		local beforecoma = math.floor(cash.Value)
		script.Parent.Amount.Text = beforecoma.."."..aftercoma" K"
	end
end)

OOF, it’s math.floor, gotta love those case-sensitive words

oh lmao didnt see that thanks man i would never notice that

1 Like