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.
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
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:
player1 invites player2 to party using event1
Server tells player2 that player1 invited them to a party using event2
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.
player2 accepts the invite, and sends a message to the server with the party they would like to join using event2.
Server validates the request (Store a table of active requests) so exploiters cannot join other peoples parties uninvited.
Add the player to the party, and if wanted, display a success UI to the player1 using the event1.
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