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

Getting the error "Attempt to compare nil and number", does anyone know how to fix this?

Asked by
u1v6 22
4 years ago
game.ReplicatedStorage.Remotes.DepositATM.OnServerEvent:Connect(function(player)        

local Wallet = player.CurrencyFolder.Wallet.Value
local Amount = tonumber(script.Parent.Parent.AMOUNT.Text)

if Wallet >= Amount then

player.CurrencyFolder.Wallet.Value = player.CurrencyFolder.Wallet.Value - Amount
player.BankFolder.Bank.Value = player.BankFolder.Bank.Value + Amount

end     
end)

Error: Attempt to compare nil and number

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

The problem is that the text only changes for the client, not the server, so you have to send the text through with the LocalScript. For example:

LocalScript


-- Insert LocalScript code here game.ReplicatedStorage.Remotes.DepositATM:FireServer(script.Parent.Parent.AMOUNT.Text)

ServerScript

game.ReplicatedStorage.Remotes.DepositATM.OnServerEvent:Connect(function(player, text)        

    local Wallet = player.CurrencyFolder.Wallet.Value
    local Amount = tonumber(text)

    if Wallet >= Amount then

        player.CurrencyFolder.Wallet.Value = player.CurrencyFolder.Wallet.Value - Amount
        player.BankFolder.Bank.Value = player.BankFolder.Bank.Value + Amount

    end     
end)

It says Attempt to compare nil and number because the text is equal to nothing on the server's side. For more information click here

0
had the same problem while ago, good answer too 123nabilben123 499 — 4y
0
Thank you so so much u1v6 22 — 4y
0
No problem youtubemasterWOW 2741 — 4y
Ad

Answer this question