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

Help on making a money transfer system?

Asked by 3 years ago

I've been trying to make a money transfer system for my game, but everything I've tried always gets this error: "Argument 1 missing or nil." This is the script firing the remote event.

receiver = script.Parent.Receiver.Text
amount = script.Parent.Amount2Send.Text
amount2send = tonumber(amount)
sendButton = script.Parent.Send
plrName = game.Players.LocalPlayer.UserId
sendButton.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.BankTransfer:FireServer(amount2send, receiver, plrName)
end)

script.Parent.Close.MouseButton1Click:Connect(function()
    script.Parent.Visible = false
end)

This is the serverscript.

game.ReplicatedStorage.BankTransfer.OnServerEvent:Connect(function(amount2send, receiver, plrName, plr)
    local sender = plrName
    local receiverID = game.Players:GetPlayerByUserId(receiver)
    local amount = amount2send
    if plr.Wallet.Value >= amount then
        plr.Wallet.Value = plr.Wallet.Value - amount
        receiverID.Wallet.Value = receiverID.Wallet.Value + amount
    end
end)

1 answer

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

One issue I noticed right of the bat is .OnServerEvent's first argument is the player instance for the player that fired the event.

RemoteEvent API:

RBXScriptSignal OnServerEvent ( Instance player , Tuple arguments )

Another thing is that if the string cannot be converted to a number, tonumber(string) will return nil, so I would add a check to make sure amount2send is not nil.

game.ReplicatedStorage.BankTransfer.OnServerEvent:Connect(function(plr, amount2send, receiver, plrName) -- changed the order of the arguments
    if amount2send == nil then warn("Amount is nil") return end -- Exit the function to prevent error
    local sender = plrName
    local receiverID = game.Players:GetPlayerByUserId(receiver)
    local amount = amount2send
    if plr.Wallet.Value >= amount then
        plr.Wallet.Value = plr.Wallet.Value - amount
        receiverID.Wallet.Value = receiverID.Wallet.Value + amount
    end
end)

If you need further assistance, feel free to contact me on Discord (phxntxsmic#2021).

Ad

Answer this question