Why I got this this error? Attempt to perform arithmetic(add) on nil and number, that really help me

I modified your code a little, if you don’t understand something, just ask me and I’ll answer as soon as possible


LocalScript

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("PlayerDetect")

local Type1 = script.Parent.Parent.TextBox
local Type2 = script.Parent.Parent.Parent.Frame.Cash

script.Parent.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer(Type1, Type2)
end)

ServerScript

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("PlayerDetect")

RemoteEvent.OnServerEvent:Connect(function(player, Type1, Type2)
	Type1 = tonumber(Type1.Text)
	Type2 = tonumber(Type2.Text)
	
	if Type1 <= Type2 and Type1 > 0 then
		player.leaderstats.Cash.Value += Type1
	else
		print("Not enough Cash")
	end
end)

I hope it works, I didn’t have time to test

1 Like

In the first line of the remote event, check if tonumber(TextBox.Text), add an else for this that changes the text to “No Number Found” and resets the text