RemoteFunction.OnServerInvoke not firing

I have a remote function: ReplicatedStorage.RemoteFunctions.Party.GetInvites

In a LocalScript I’m trying to fetch invites for the LocalPlayer

openPartyInvitesButton.MouseButton1Click:Connect(function()
    if not invitesFrame.Visible then
        InvitesGUIUtils:RefreshList()

        invitesNotificationsCountLabel:SetAttribute("UnreadCount", 0)
        invitesNotificationsCountLabel.Text = "0"
        invitesNotificationsCountLabel.Visible = false
    end

    invitesFrame.Visible = not invitesFrame.Visible
end)

ModuleScript: InvitesGUIUtils:RefreshList()

local PartyUtils = require(ReplicatedStorage.Utils.Party.PartyUtils)

local module = {}

function module:RefreshList()
    print("Get invites")

    local invites = PartyUtils:GetInvites()

    print(invites)
end

return module

ModuleScript: PartyUtils:GetInvites()

local getInvitesFunction = ReplicatedStorage.RemoteFunctions.Party.GetInvites

local module = {}

function module:GetInvites(): { number }
    print("[Utils]: Get invites")

    return getInvitesFunction:InvokeServer()
end

return module

Server script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local PartyService = require(ServerStorage.Services.PartyService)
local getInvitesFunction = ReplicatedStorage.RemoteFunctions.Party.GetInvites

function getInvitesFunction.OnServerInvoke(player)
    print("Get invites")

    return PartyService:GetPlayerInvites(player)
end

ModuleScript: PartyService:GetPlayerInvites(player)

local module = {}

function module:GetPlayerInvites(player: Player): { number }
	local invites = {}

	for _, party in pairs(parties) do
		if table.find(party.invitedPlayers, player) then
			table.insert(invites, party.ownerId)
		end
	end

	return invites
end

return module

Output:

Get invites  -  Client - InvitesGUIUtils:18
[Utils]: Get invites  -  Client - PartyUtils:23

As you can see getInvitesFunction.OnServerInvoke is not being fired because Get invites is not being printed to the output, although it is clearly invoked. I even tested with the debugger and it gets to the line return getInvitesFunction:InvokeServer().

Why is the server not receiving the event?

Perhaps you meant GetInvitesFunction.OnServerInvoke = function(...)?

It’s a callback.

There’s no difference, you can assign the callback both ways.

Turned out I had two scripts listening to the callback and this was casuing the issue.

Right, I almost forgot… Anyways.

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