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

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

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

✓ Accepted answer

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

3 comments

0

had the same problem while ago, good answer too

0

Thank you so so much

0

No problem

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