Hi, I have hit a curb nearing the completion of a peer-to-peer currency transfer script, and would like some help with this error I can’t figure out how to resolve.
My currency script has 2 parts.
- The StarterGUI which provides the interface paired with a local script
- The Serverscript which provides the currency change
The local script in the UI toggles a remote event, titled SendValues.
Heres the important snippet of the Local Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local remoteFunction = ReplicatedStorage:WaitForChild("SendValues") script.Parent.Send.MouseButton1Down:connect(function() if Sender.leaderstats.Cash.Value >= (tonumber (Amount)) then if game.Players:FindFirstChild(Recipient) then print(Recipient, Sender, Amount) -- Invoke the function local sendmoney = remoteFunction:FireServer(Recipient, Sender, Amount) print ('Fired Server')
Initially, it prints the Recipient, Sender, and Amount correctly. According to output, this script is totally fine.
local ReplicatedStorage = game:GetService("ReplicatedStorage") local remoteFunction = ReplicatedStorage:WaitForChild("SendValues") remoteFunction.OnServerEvent:Connect(function(Sender, Recipient, Amount) print(Sender, Recipient, Amount) Sender.leaderstats.Cash.Value -= (tonumber (Amount)) print('Removed Cash from Sender') game.Players:FindFirstChild(Recipient).leaderstats.Cash.Value += (tonumber (Amount)) print('Gave Cash to Recipient') end)
Here, everything goes haywire.
Firstly, the values printed are incorrect. In the local script, it could print:
imaxZulu832, imaxZulu832, 12000
In the server script it prints:
imaxZulu832, imaxZulu832, imaxZulu832.
Secondly, an error shows up.
‘attempt to perform arithmetic (sub) on number and nil’
I assume this means that the amount was replaced with the wrong value, as above.
Any help will be much appreciated, thanks.