Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

"attempt to compare nil with number" ?

Asked by 5 years ago

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)
0
What kind of value is "cash" on line 13? noammao 294 — 5y
0
It's an Int Value JJBIoxxer 50 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

Checking for amount

if cash => "*AMOUNT HERE*" then 

elseif cash <= print (Not enough money)
0
Doesn't explain anything... JJBIoxxer 50 — 5y
0
It's for the amount the of cash, before it takes the money. AlertShamrock 37 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

Answer this question