InvokeClient not returning anything

I’m trying to make a party invite system of which a requester, invokes the server with a player name, then the server invokes the client, asking to accept or decline using a gui, but upon invoking the requestee, it never yields or anything and it doesn’t return anything, why?
The UI button is being clicked but it still returns nil and doesn’t yield at all.
image

local Response = nil
local Additional = nil
Response, Additional = InviteClient:InvokeClient(Requestee, Inviter.Name)
for i = 1, 10 do
	print(Response)
	if Response ~= nil then
		break
	end
	task.wait(1)
end

On the documentation for RemoteFunctions, it states that remote events should probably be used for this instance.

Something you can do as a solution, is to have two RemoveEvents that manage the system.

Have 1 event to send invites, and one to display the UI and accept them.

Example:

  1. player1 invites player2 to party using event1

  2. Server tells player2 that player1 invited them to a party using event2

  3. player2’s UI displays a invite frame, with a button to join or close the popup.
    player2 cannot recieve any other invites while this menu is up, and the menu will auto-close after 20 seconds.

  4. player2 accepts the invite, and sends a message to the server with the party they would like to join using event2.

  5. Server validates the request (Store a table of active requests) so exploiters cannot join other peoples parties uninvited.

  6. Add the player to the party, and if wanted, display a success UI to the player1 using the event1.

1 Like

I just gave up on using InvokeClient and revoked to FireClient instead, I only needed InvokeClient to alert if the requestee decline or not.

Weakroblox lets try and sort this out, so you know for the future

can you send the client code

ClientReceived.OnClientInvoke = function(Requester)
	local GUI = ReplicatedStorage.Storage.UIs.Request:Clone()
	GUI.Frame.Req.Text = Requester
	GUI.Parent = Player.PlayerGui
	GUI.Frame.Accept.MouseButton1Down:Connect(function()
		--
		return true
	end)
	GUI.Frame.Decline.MouseButton1Down:Connect(function()
		--
		return false
	end)
end

is the for loop running before the response receiving anything

its running after invoking client and its used a timeout

who is the requestee? are you sure its going to the right player

alr I see whats happening, need to add yield of some type because function is not waiting until something is returned

Basically

its not waiting until something is pressed before returning it back to server hence why its nil

So for example you can do something like this

ReplicatedStorage.RemoteFunction.OnClientInvoke = function()
	local info = nil
	HUDFrame.ButtonFolder.Trade.MouseButton1Click:Connect(function()
		info = true
	end)
	
	repeat task.wait(1) until info  ~= nil
	return info
end

You should use a callback mechanism to handle the client’s response.

Sever script:


local InviteEvent = Instance.new("RemoteEvent")
InviteEvent.Name = "InviteEvent"
InviteEvent.Parent = game.ReplicatedStorage

function InvitePlayer(requester, requestee)
    local responseEvent = Instance.new("RemoteEvent")
    responseEvent.Name = "ResponseEvent"
    responseEvent.Parent = requestee

    local function onResponse(playerName, response)
        if playerName == requestee.Name then
            responseEvent:Destroy()
            InviteEvent:FireClient(requester, playerName, response)
        end
    end

    responseEvent.OnServerEvent:Connect(onResponse)
    responseEvent:FireClient(requestee, requester.Name)
end

InviteEvent.OnServerEvent:Connect(function(player, requesteeName, response)
    print(player.Name .. " received a response from " .. requesteeName .. ": " .. response)

Client Script:

local InviteEvent = game.ReplicatedStorage.InviteEvent

local ResponseEvent = Instance.new("RemoteEvent")
ResponseEvent.Name = "ResponseEvent"
ResponseEvent.Parent = game.ReplicatedStorage

local playerName = game.Players.LocalPlayer.Name
local requester = nil

local function onInviteReceived(inviterName)
    -- Display a UI prompting the player to accept or decline the invitation
    -- You can implement your UI logic here and set the `response` variable accordingly
    local response = "Accept" -- Set this based on the player's choice

    ResponseEvent:FireServer(playerName, response)
end

InviteEvent.OnClientEvent:Connect(onInviteReceived)
end)

I think InvokeClient might be deprecated, who knows
Unless there is some uses but i think due to Roblox trying to prevent exploiting, it’s likely InvokeClient will be removed and marked as deprecated