RemoteFunction not working

Hello there, everyone. I’m currently working on a trade system but for some reasons the RemoteFunction isn’t working.

Here’s the local script:

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Text = "SENT"
	local Sending = game.ReplicatedStorage.Trade.RequestTradeToPlayer:InvokeServer(script.Parent.Name)
	wait(2)
	script.Parent.Text = "TRADE"
end)

Here’s the server script:

local function SendRequest(Player, PlayerRequested)
	print("[TEST]: " .. Player.Name .. " sent a trade request to " .. PlayerRequested .. "!")
end

game.ReplicatedStorage.Trade.RequestTradeToPlayer.OnServerInvoke = SendRequest

Any ideas why it isn’t working?

1 Like

You never specified what player requested was. Also you incorrectly invoked the remote event. You can’t invoke it in a variable. It should be

local variable_name location_to_remoteevent
variable_name:InvokeServer()

Is the remote function found in Replicated Storage?
Is it named correctly?

Does it return any errors? Because it works fine for me.

Also, he is right you need to specify your player request variable because you are sending it as a parameter, but not declaring it anywhere.

No, that part is correct because you attach a function to OnServerInvoke by just referencing the function. If you use SendRequest() instead of SendRequest, it just calls the function instead of assigning it to OnServerInvoke which will raise an error.

1 Like

You need to return something in the server. InvokeServer/InvokeClient will yield the code until it gets a returned value

local function SendRequest(Player, PlayerRequested)
	print("[TEST]: " .. Player.Name .. " sent a trade request to " .. PlayerRequested .. "!")
    return true -- this value goes back to the client and will be specified as "Sending" as indexed in the code
end

game.ReplicatedStorage.Trade.RequestTradeToPlayer.OnServerInvoke = SendRequest
3 Likes

The problem is that the RemoteFunction isn’t firing.

script.Parent.MouseButton1Click:Connect(function()
	local Request = game.ReplicatedStorage.Trade.RequestTradeToPlayer:InvokeServer(script.Parent.Parent.Name)
	script.Parent.Text = "SENT"
	print("Request sent!")
	wait(2)
	script.Parent.Text = "TRADE"
end)

For some reasons, this code isn’t working.

Use print debug. Try to find out which code line stops firing the print function.

1 Like

First of all, place print statements in your code for debugging till where the code is running. Also check if there are any errors in the output.


@RobloxTitan4223 It doesn’t need to be like that, the reason the OP has done it like that is because Remote Functions return a value which will need to be assigned to a variable. Again, its not a remote event, its a remote function.

1 Like

Lol, I forgot it’s a remote function. My bad

1 Like