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

"attempt to compare nil with number" ?

So I'm trying to check if the player has enough to bet before it takes their coins. The check keeps sending an error. I have done this same check on several other things but this one errors. Can anyone help?

local Player = game.Players.LocalPlayer
local Sample = script.Sample
local Bet = script.Parent.Bet.Input.Text
local Accept = script.Parent.Accept
local Players = script.Parent.Players.ScrollingFrame
local Timer = script.Parent.Timer
local Total = script.Parent.Total

local Decrement = game.ReplicatedStorage.Events.Decrement

Accept.MouseButton1Click:Connect(function()
	if Bet.Text ~= "" then
		if Player.Cash.Value >= tonumber(Bet.Text) then -- This is sending the error.
			Decrement:FireServer("Cash",tonumber(Bet.Text))
			local Clone = Sample:Clone()
			Clone.Parent = Players
			Clone.Username.Text = Player.Name
			Clone.Bet.Text = "$" .. Bet.Text
		end
	end
end)

2 comments

0

What kind of value is "cash" on line 13?

0

It's an Int Value

2 answers

Checking for amount

if cash => "*AMOUNT HERE*" then 

elseif cash <= print (Not enough money)

2 comments

0

Doesn't explain anything...

0

It's for the amount the of cash, before it takes the money.

Found the issue nvm lol When I made the bet variable I put in

local Bet = script.Parent.Bet.Input.Text

instead of

local Bet = script.Parent.Bet.Input

So when I was calling "Bet.Text" in the if statment it was searching for Text.Text lol

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