Request System Between 2 Players Not Working

Im trying to make a system where for example: Player1 can send a request to Player2. Once Player2 receives this request with OnClientInvoke(), a GUI is supposed to appear to give the option to accept or deny the request.
This is done by a single remote event (Named: RequestHandler)
I’m trying to make Player1 send a request to the server with RequestHandler, then the server sends a request to Player2 using again, RequestHandler.
This happens between 3 scripts, which will be shown later.

However, when the button is pressed to send the request via InvokeServer(), nothing happens.
No error is thrown in the Output and the GUI doesn’t appear or change at all.

Local Script 1This is where the button is pressed by Player1 to send the request to the server via InvokeServer() … step 1 of the process

local sendRequestButton = script.Parent
local remoteFunctions = game.ReplicatedFirst.RemoteFunctions

sendRequestButton.MouseButton1Click:Connect(function(plr)
	
	local sentByPlayerID = game.Players:GetUserIdFromNameAsync(game.Players.LocalPlayer.Name)
	local selectedPlayerID = script.Parent.SelectedPlayerID.Value
	
	local requestResult = remoteFunctions.RequestHandler:InvokeServer(selectedPlayerID, sentByPlayerID)
	
	
end)

Script 1This is where the Server Receives the initial request, then sends the actual request to the client (Player2) via InvokeClient() … step 2

local remoteFuncitons = game.ReplicatedFirst.RemoteFunctions

remoteFuncitons.RequestHandler.OnServerInvoke = function(selectedPlayerID, sentByPlayerID)
	local clientName = game.Players:GetNameFromUserIdAsync(selectedPlayerID)

	local requestResult = remoteFuncitons.RequestHandler:InvokeClient(clientName,selectedPlayerID,sentByPlayerID)

	return requestResult
end

Local Script 2This is where Player2 receives the request from the server, and attempts to make the GUI Visible and fill in all the necessary information, completing the process … Step 3

local remoteFunctions = game.ReplicatedFirst.RemoteFunctions
local requestUI = script.Parent.RequestUI

remoteFunctions.RequestHandler.OnClientInvoke = function(selectedPlayerID, sentByPlayerID)
	
	requestUI.Name.Text = game.Players:GetNameFromUserIdAsync(game.Players:GetNameFromUserIdAsync(sentByPlayerID))
	requestUI.UserIcon.Image = game.Players:GetUserThumbnailAsync(sentByPlayerID, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
	requestUI.Visible = true
	
	for i = 5, 0, -1 do
		
		requestUI.YesButton.MouseButton1Click:Connect(function()
			requestUI.Click:Play()
			requestUI.Visible = false
			return true
		end)
		
		requestUI.NoButton.MouseButton1Click:Connect(function()
			requestUI.Click:Play()
			requestUI.Visible = false
			return false
		end)
		
		requestUI.CountDown.Text = string.format(i)
		wait(1)
	end
	
end

To clarify, no error is thrown in the Output and nothing happens to the GUI…

Any thoughts and ideas are welcomed. Sorry for messy scripts as Im still building most of it. Hopefully this post is coherent as I have been working on this for hours and im starting to get tired :frowning:
Thank you for any and all help!!!

2 Likes

In Script 1, the first parameter to the OnServerInvoke is by default the player that invoked the server, which you forgot to add as a parameter

local remoteFuncitons = game.ReplicatedFirst.RemoteFunctions

remoteFuncitons.RequestHandler.OnServerInvoke = function(senderplr, selectedPlayerID, sentByPlayerID)
	local clientName = game.Players:GetNameFromUserIdAsync(selectedPlayerID)

	local requestResult = remoteFuncitons.RequestHandler:InvokeClient(clientName,selectedPlayerID,sentByPlayerID)

	return requestResult
end
1 Like

Unfortunately I updated this part of the script and nothing happened. No error, and nothing happened to the GUI

1 Like

also in script 1 when you invokeclient the first parameter should be the player object instead of the player name

local remoteFuncitons = game.ReplicatedFirst.RemoteFunctions

remoteFuncitons.RequestHandler.OnServerInvoke = function(senderplr, selectedPlayerID, sentByPlayerID)
	local clientPlr = game.Players:GetPlayerByUserId(selectedPlayerID)

	local requestResult = remoteFuncitons.RequestHandler:InvokeClient(clientPlr,selectedPlayerID,sentByPlayerID)

	return requestResult
end
1 Like

Updated this. Still nothing happens. I’m using the print function to see what’s being executed and what is not.

I found that nothing is happening is happening after this line in Local Script1:

local requestResult = remoteFunctions.RequestHandler:InvokeServer(selectedPlayerID, sentByPlayerID)

I also found that nothing is happening in Script1 and LocalScript2 (besides the first 2 lines)

1 Like

This is what is printed in the output when I click the button to start the request process::

RH1 - Server - RequestHandlerScript:2
RR1 - Client - ReceiveRequest:3
SR1 - Client - SendingOutRequests:5
SR2 - Client - SendingOutRequests:8

RH1 Shows that the first 2 lines of code work in Script1
RR1 Shows that the first 2 lines of code work in LocalScript2
SR1 & SR2 Shows that the function in LocalScript1 works up until:

local requestResult = remoteFunctions.RequestHandler:InvokeServer(selectedPlayerID, sentByPlayerID)
1 Like

Update: Using 2 remote functions did not solve the problem. I also tried moving Script1 into Serverstorage as opposed to ServerScriptService.

Both these attempts yield the same result

1 Like

what’s the output of this?

-- local script 1

local sendRequestButton = script.Parent
local remoteFunctions = game.ReplicatedFirst.RemoteFunctions

sendRequestButton.MouseButton1Click:Connect(function(player)
	print("clicked")

	local selectedPlayerID = script.Parent.SelectedPlayerID.Value
	local requestResult = remoteFunctions.RequestHandler:InvokeServer(selectedPlayerID)

	print("sent request")
end)
-- script 1

local Players = game:GetService("Players")
local remoteFuncitons = game.ReplicatedFirst.RemoteFunctions

remoteFuncitons.RequestHandler.OnServerInvoke = function(player, selectedPlayerID)
	print("function invoked on server")
	local client = Players:GetPlayerByUserId(selectedPlayerID)

	if not client then
		warn("no client")
		return false
	end

	local requestResult = remoteFuncitons.RequestHandler:InvokeClient(client, player)

	return requestResult
end
-- local script 2
local remoteFunctions = game.ReplicatedFirst.RemoteFunctions
local requestUI = script.Parent.RequestUI

remoteFunctions.RequestHandler.OnClientInvoke = function(sentByPlayer)
	print("got request on client 2")

	requestUI.Name.Text = sentByPlayer.Name
	requestUI.UserIcon.Image = game.Players:GetUserThumbnailAsync(sentByPlayer.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
	requestUI.Visible = true

	for i = 5, 0, -1 do
		requestUI.YesButton.MouseButton1Click:Connect(function()
			requestUI.Click:Play()
			requestUI.Visible = false
			return true
		end)

		requestUI.NoButton.MouseButton1Click:Connect(function()
			requestUI.Click:Play()
			requestUI.Visible = false
			return false
		end)

		requestUI.CountDown.Text = string.format(i)
		task.wait(1)
	end
end
1 Like

All that is outputted is “Clicked”

1 Like

Where is script 1? Can you screenshot the explorer view?

1 Like

image
I’ve tried moving it to ReplicatedStorage and ReplicatedFirst

1 Like

just curious, what happens with this?

-- local script 1

local sendRequestButton = script.Parent
local remoteFunctions = game.ReplicatedFirst.RemoteFunctions

sendRequestButton.MouseButton1Click:Connect(function(player)
	print("clicked")

	local requestResult = remoteFunctions.RequestHandler:InvokeServer()
	local selectedPlayerID = script.Parent.SelectedPlayerID.Value

	print("sent request")
end)
1 Like

Try moving your RemoteFunctions folder to ReplicatedStorage instead

-- local script 1

local sendRequestButton = script.Parent
local remoteFunctions = game.ReplicatedStorage.RemoteFunctions

sendRequestButton.MouseButton1Click:Connect(function(player)
	print("clicked")

	local requestResult = remoteFunctions.RequestHandler:InvokeServer()
	local selectedPlayerID = script.Parent.SelectedPlayerID.Value

	print("sent request")
end)
-- script 1

local Players = game:GetService("Players")
local remoteFuncitons = game.ReplicatedStorage.RemoteFunctions

remoteFuncitons.RequestHandler.OnServerInvoke = function(player, selectedPlayerID)
	print("function invoked on server")
	local client = Players:GetPlayerByUserId(selectedPlayerID)

	if not client then
		warn("no client")
		return false
	end

	local requestResult = remoteFuncitons.RequestHandler:InvokeClient(client, player)

	return requestResult
end
-- local script 2
local remoteFunctions = game.ReplicatedStorage.RemoteFunctions
local requestUI = script.Parent.RequestUI

remoteFunctions.RequestHandler.OnClientInvoke = function(sentByPlayer)
	print("got request on client 2")

	requestUI.Name.Text = sentByPlayer.Name
	requestUI.UserIcon.Image = game.Players:GetUserThumbnailAsync(sentByPlayer.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
	requestUI.Visible = true

	for i = 5, 0, -1 do
		requestUI.YesButton.MouseButton1Click:Connect(function()
			requestUI.Click:Play()
			requestUI.Visible = false
			return true
		end)

		requestUI.NoButton.MouseButton1Click:Connect(function()
			requestUI.Click:Play()
			requestUI.Visible = false
			return false
		end)

		requestUI.CountDown.Text = string.format(i)
		task.wait(1)
	end
end
2 Likes

Still prints just “Clicked”, im trying the second reply now

1 Like

Moving the remote functions to replicated storage seems to have worked… Im now getting errors and the following prints:
“Clicked”
“Functions Invoked on Server”
then the errors occured

I wonder why having the remote functions in replicated first was the problem…weird…

1 Like

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