Table from RemoteFunction returns nil, but passes through a table.find() statement?

  1. What do you want to achieve? I’m trying to make a permissions system, I wan’t a player menu listing the player’s with their permissions.

  2. What is the issue? I get the permissions table from a ModuleScript using a RemoteFunction, and search for the player’s name in the table, for some reason it got past a table.find() statement locally, but when I try RemoteFunction[player.Name], it returns nil?

  3. What solutions have you tried so far? I couldn’t find any unfortunately.

local getplayers = game.ReplicatedStorage.CheckAllPerms:InvokeServer()

game.ReplicatedStorage.CreatePlayer.OnClientEvent:Connect(function(player, creating)
	if creating == true then
		if table.find(getplayers, player.Name) then
			local playerFrame = script.TwentyCharactersLong:Clone()
			playerFrame.Name = player.Name
			playerFrame.PlayerPFP.Image = game.Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
			if getplayers[player.Name] == 0 then
				playerFrame.PlayerName.Text = player.Name.." (Visitor)"
				print("0")
			elseif getplayers[player.Name] == 1 then
				playerFrame.PlayerName.Text = player.Name.." (Builder)"
				print("1")
			elseif getplayers[player.Name] == 2 then
				playerFrame.PlayerName.Text = player.Name.." (Admin)"
				print("2")
			elseif getplayers[player.Name] == 3 then
				playerFrame.PlayerName.Text = player.Name.." (Creator)"
				print("3")
			elseif getplayers[player.Name] == 4 then
				playerFrame.PlayerName.Text = player.Name.." (Game Moderator)"
				print("4")
			elseif getplayers[player.Name] == 5 then
				playerFrame.PlayerName.Text = player.Name.." (Game Admin)"
				print("5")
			elseif getplayers[player.Name] == 6 then
				playerFrame.PlayerName.Text = player.Name.." (Game Creator)"
				print("6")
			end
			playerFrame.LayoutOrder = getplayers[player.Name]
			playerFrame.Parent = script.Parent
		end
	end
end)

table.find() raises an error if the first argument passed to it is not a table value, try printing (getplayers) before the table.find() operation occurs.

image
Why is 2 not mixed with 1?

game.ReplicatedStorage.CheckAllPerms.OnServerInvoke = function(player)
	local returning = {}
	for _, v in pairs(require(game.ReplicatedStorage.Perms)) do
		table.insert(returning, v)
	end
	return returning
end
local permissions = {
	["simo066u"] = 5, -- Game Admin
	["Include_Viable"] = 4, -- Game Moderator
}

return permissions
local permissions = require(game.ReplicatedStorage.Perms)

game.Players.PlayerAdded:Connect(function(player)
	if not table.find(permissions, player.Name) then
		if player.UserId ~= game.CreatorId then
			local insertedItem = table.insert(permissions, player.Name)
			permissions[player.Name] = 0 -- Visitor
		elseif player.UserId == game.CreatorId then
			local insertedItem = table.insert(permissions, player.Name)
			permissions[player.Name] = 3 -- World Creator
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	if table.find(permissions, player.Name) then
		for i, v in pairs(permissions) do
			if v == player.Name then
				table.remove(permissions, i)
			end
		end
	end
end)

The player Instance is not sent through to the client when OnClientEvent is connected to a function because the client is able to reference the player instance directly through the Players service at any time with game:GetService("Players").LocalPlayer.

This means that the “player” parameter in the function from your original post would actually be referring to the second parameter that was input to the :FireClient() method on the server.


In short, the LocalPlayer can be referenced when needing to access player.Name and the “player” parameter within the function on the client-side can be removed.

local Players = game:GetService("Players")
local player = Players.LocalPlayer

game.ReplicatedStorage.CreatePlayer.OnClientEvent:Connect(function(creating)
    -- Continue with the function
end)

Yeah but, if I did that there would be multiple of me in the player frame instead of 5 other people