RemoteFunction returning nil even though value before returned isn't?

Hello, I’m currently trying to access another clients PlayerGui through another client. I have a remote function that fires to the server with the client asking for the data and the name of the player. The server then fires the remote function to the name of the player and returns their gui. In the server the value returns as the gui. However, when the client who asked for the data receives it, it is nil.

The function that asks for the data within the client:

local joinGUI = script.Parent.Parent
	local gui = player.PlayerGui.MainLobby.Background
	local createdLobby = game.ReplicatedStorage.LobbySystem.RetreivingLobbyInformation:InvokeServer(joinGUI.PlayerName.NameOfPlayer.Text)
	if createdLobby then
		--Adds all players inside the current lobby
		for _, joinedPlayer in pairs(createdLobby.JoinedPlayers:GetChildren()) do
			if joinedPlayer:IsA("Frame") then
				local clone = joinedPlayer:Clone()
				joinedPlayer.Parent = script.Parent.JoinedPlayers
			end
		end

		gui.CreatedLobby.Visible = true
		gui.CreatedLobby.Join.Visible = false

	end

The server side:

folder.RetreivingLobbyInformation.OnServerInvoke = function(firedPlayer, lobbyOwner)
	local lobbyOwner = game.Players:FindFirstChild(lobbyOwner)
	if firedPlayer == nil then return end
	if lobbyOwner then
		local information = folder.RetreivingLobbyInformation:InvokeClient(lobbyOwner, firedPlayer)
		print(information)
		return information
	end
end

The receiving client side:

game.ReplicatedStorage.LobbySystem.RetreivingLobbyInformation.OnClientInvoke = function(firedPlayer)
	return createdLobby
end

Like I said when the server prints information it returns with the value, but somehow it returns nil when it returns it back to the client.

I think it’s because RemoteFunctions can’t send instances that aren’t replicated. And playerA’s ui isn’t replicated to playerB.

A simple solution should be adding :Clone(). Though I’m not sure if that will work.

But really you should be creating the ui on the receiving player, or atleast the server. Otherwise hackers can create ui and send it to other players to do malicious things.

1 Like

local createdLobby = game.ReplicatedStorage.LobbySystem.RetreivingLobbyInformation:InvokeServer(joinGUI.PlayerName.NameOfPlayer.Text)
if createdLobby then
–Adds all players inside the current lobby
for _, joinedPlayer in pairs(createdLobby.JoinedPlayers:GetChildren()) do
if joinedPlayer:IsA(“Frame”) then
local clone = joinedPlayer:Clone()
joinedPlayer.Parent = script.Parent.JoinedPlayers
end
end

gui.CreatedLobby.Visible = true
gui.CreatedLobby.Join.Visible = false

end

The reason why, is because the player object is not a datatype that can be replicated. Only strings, numbers, booleans, and tables are.

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