Remote Event won't work

Hello, I made some scripts with a Remote Event and it’s for an admin script

(I tried looking for similar problems like this but I couldn’t understand most of the time so I’m asking for help)

What it’s supposed to do is the player types the cash Amount in a TextBox and the Player’s name in another TextBox. Once that’s done, it sends a signal to a script to give the Player’s Name (TextBox) the amount of cash in the Cash Textbox. The problem is, I tried this but I’ve come to see that I’ve gotten the error
ServerScriptService.AdminScripts.ConnectRemotes:8: attempt to concatenate Instance with string
but all that gave me was the print.
I really don’t know much about Remote Events so if you could help then that would help me alot!
Scripts:

Local Script: Button

local cBox = script.Parent.Parent.CashTextBox
local pBox = script.Parent.Parent.PlayerTextBox
local button = script.Parent

local rStorage = game:GetService("ReplicatedStorage")
local folder = rStorage:WaitForChild("adminEvents")
local remoteC = folder:WaitForChild("cashRemote")

local Players = game:GetService("Players")
local plr = Players.LocalPlayer

button.MouseButton1Click:Connect(function()
	remoteC:FireServer(plr, tonumber(cBox.Text), pBox.Text)
	print("Signal CASH Sent. CASH: "..cBox.Text.." | TO PLAYER: "..pBox.Text)
end)

Server Script: ServerScriptService INSIDE Folder


local rStorage = game:GetService("ReplicatedStorage")
local folder = rStorage:WaitForChild("adminEvents")
local remoteC = folder:WaitForChild("cashRemote")

remoteC.OnServerEvent:Connect(function(sender, cashAmount, playerName)
	print("SIGNAL DETECTED: "..sender.Name.." SENT $"..cashAmount.."TO "..playerName)
	for _, plr in ipairs(Players:GetPlayers()) do
		if plr.Name == playerName then
			plr:FindFirstChild("Cash").Value += cashAmount
			print("PLAYER FOUND, GIVING $"..cashAmount)
		else
			warn("USER "..plr.." DOESN'T MATCH "..playerName)
		end
	end
end)

If I made any mistakes OR I need to improve something in the script then you could tell me and I’d try it.

Your error may be on this line. Trying doing plr.Name instead.

Also, you do not need to pass plr.

since the first has to be a player, Should I replace it with the pBox.Text?
or is there any other way?

I’ve re-edited the script, I figured I could use

remoteC.OnServerEvent:Connect(function(playerName, cashAmount)
 if playerName then
		playerName:FindFirstChild("Cash").Value += cashAmount
		end
end)

and this on the LocalScript

remoteC:FireServer(Players:FindFirstChild(pBox.Text), cBox.Text)

So now I’m having trouble turning the cashAmount into a number while I keep getting the error
“attempt to perform arithmetic (add) on number and nil”

I am not sure what you mean. From my understanding you are trying to make something for your admin panel which will give another player Cash, correct? When you use :FireServer(), the player who calls the remote is automatically passed. The way you used :FireServer() is making bother the sender and cashAmount arg the player who called the remote. Once you fix the two things I’ve mentioned in my other post it should work.

Try to do
playerName:FindFirstChild("Cash").Value += tonumber(cashAmount)

I’ve attempted it and I got the error
attempt to perform arithmetic (add) on number and nil
Anything for this?

attempt to perform arithmetic (add) on number and nil means something is wrong with your “Cash” value or your cashAmount value. You can try debugging it by printing things.

Also, I just looked at one of your other replies and think you should fix this.
Instead of remoteC.OnServerEvent:Connect(function(playerName, cashAmount) do remoteC.OnServerEvent:Connect(function(plr, playerName, cashAmount)

If you need help on how to use RemoteEvents, I suggest watching a YouTube video as they can explain everything better than me, lol.

you’re firing the remote with your own player as an argument, you’re not supposed to do that

get rid of “plr,” on the client, but not on the server

2 Likes

Thanks, I’ve tried it and It helped me
The Scripts works

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.