RemoteFunctions with parameters

Hello,

I was looking to pass parameters through a RemoteFunction but I’m not aware of how to do so.

I know the syntax is like this:

local function OnInvoke(Player)
    print("Hello world!")
end

event.OnServerInvoke = OnInvoke

So using something like = OnInvoke(p1,p2) wouldn’t work.

How can I do this?

You would have to do something like:

--Local script
remoteFunction:InvokeServer("Print this", "and this") --Send Parameters

--Server script
local function OnInvoke(player, message1, message2) --Received Parameters
   print(message1, message2)
end

event.OnServerInvoke = OnInvoke
1 Like

Seems like this didn’t fix my issue.

--Local
	local data = game.ReplicatedStorage.Remotes.Check:InvokeServer(tostring(script.Parent.ID.ContentLabel.Text), 1)
---Server

local function OnInvoke(p, Player,Intent,Table)
	if Intent == 1 then --Check status
		local data = BannedPlayers:GetAsync(Player.UserId.."_BanV1")
		return data
        -- I cut out a lot here.		
	end
end

game.ReplicatedStorage.Remotes.Check.OnServerInvoke = OnInvoke

p is the player you are receiving the message from. If you aren’t returning anything, use a RemoteEvent instead. Also, you cannot send a Player through a Remote, since it is an instance. You can only send the player’s name.

Oh, well that would be my issue. I’m trying to find a UserId from a string :man_facepalming:

Thanks for the help.