How to insert one Player in Table after "...MouseButton1Click:Connect(function()" in Local-Script

How to insert just one Player in the table after “…MouseButton1Click:Connect(function)” in the Local-Script. I made the whole script, when i click on the Gui it send a RemoteEvent to the Server-Script and then insert Players to the table. The problem is, its insert all Players to the table but i want just one player is inserting to the table.

Example-Script:

local exampleTable = {}

game.ReplicatedStorage.example.OnServerEvent:Connect(function(player)

for i, player in pairs(game.Players:GetPlayers()) do --Must i change this?

if player then

			table.insert(exampleTable,player)
			print("example")

end
end
end

I want just insert one Player in the Table. Thanks.

Thanks for the answer and hm idk… ah yes i forgott that but how can i change it?

sorry I read your question wrong

do you want to put in the player who called the remote event?

Yeah i mean i want put that Player in the table

then just remove the for loop.

1 Like

ok then just do this

local exampleTable = {}

game.ReplicatedStorage.example.OnServerEvent:Connect(function(player)
    table.insert(exampleTable, player)
end

if you want to put in a random player then do this

local exampleTable = {}

game.ReplicatedStorage.example.OnServerEvent:Connect(function(player)
    local Players = game.Players:GetPlayers()
    local RandomPlayer = Random.new():NextInteger(1, #Players)
    table.insert(exampleTable, Players[RandomPlayer])
end

if you want it so you can’t have multiple of the same player tell me

1 Like

Ah okay thanks, it worked. Thank you much and @D0RYU thank you also for your help.

Thank you for you help! And thanks for the Random Player Script, i need that too, thanks!

no problem, if you need more help just tell me

1 Like

Ah and i have one more quastion… How can i see if a player is in the table? When “…MouseButton1Click:Connect(function())” then i want to Remove the player in the table but i have multiple Tables.

game.ReplicatedStorage.exampleEnd.OnServerEvent:Connect(function(player)

for i, player in pairs(example1) do

	table.remove(example1,player)
	print("Remove1")
--else?
	for i, player in pairs(example2) do
		table.remove(example2,player)
		print("Remove2")


	end
end

end)

Sorry for the questions ahaha

if table.find(TableWithPlayers, Player) then
    print(Player.." exists in the table")
end

Ah okay, i had already tried it but it dont worked i try it again, thanks