How would I pass a table from the Server to the Client instead of Client to Server

Hey! Just wanna give you some bonus stuf.
As @Ponzimus said, the remote may have been fired before the player joined. wait() is a good solution, and there’s another I’d like to add.

You can wait until a player is added, then let the game loop run when a player is found. Usually, the server runs before the player joins the game, so… that happens.

--Add this before the main loop
--Use a variable and wait for the player, have the player not joined already.
local plrs = game:GetService("Players")
local chkForFirst = #(plrs:GetPlayers()) <= 0 and plrs.PlayerAdded:Wait()

You can also add a player count check in the loop, see if there’s enough players in the server, then when the player count exceeds the minimum player count, the loop continues.

This would be better if you wait until the player is loaded, send the request to the server, and the game starts. Good luck with your game!

2 Likes

As you are sending this to the client, on the OnClientEvent listener, you don’t need to pass player in

-- old code, look at Player in this, and look at what `ColorTable` returns, nil? It's because player in this case is
-- actually colorTable
game.ReplicatedStorage.SideBar.GiveColoursToClient.OnClientEvent:Connect(function(player,ColorTable)
	for index, value in ipairs(ColorTable) do -- Invalid argument to `ipairs` (table expected, got nil)
		print(index, value) 
	end
end)

-- fixed code, drop the argument `player`, or replace it with `ColorTable` and remove the original
game.ReplicatedStorage.SideBar.GiveColoursToClient.OnClientEvent:Connect(function(ColorTable)
	for index, value in ipairs(ColorTable) do
		print(index, value)  -- Expected code
	end
end)
2 Likes

I still have a small problem. because I am making a level generated kind of game like tower of hell. I wanted to pass colour values to the table did not work so I tried with color name.

here is the script updated:

local frame1 = script.Parent.SideBarFrame.Frame1
local frame2 = script.Parent.SideBarFrame.Frame2
local frame3 = script.Parent.SideBarFrame.Frame3
local frame4 = script.Parent.SideBarFrame.Frame4
local frame5 = script.Parent.SideBarFrame.Frame5
local frame6 = script.Parent.SideBarFrame.Frame6

game.ReplicatedStorage.SideBar.GiveColoursToClient.OnClientEvent:Connect(function(ColorTable)
	print("o k")
	while true do
		wait()
	if ColorTable[1] == "Lapis" then
		frame1.BackgroundColor3 = Color3.fromRGB(16, 42, 220)
		elseif ColorTable[1] == "Brown" then
			frame1.BackgroundColor3 = Color3.fromRGB(124, 92, 70)
		elseif ColorTable[1] == "Neon Orange" then
			frame1.BackgroundColor3 = Color3.fromRGB(213, 115, 61)
		elseif ColorTable[1] == "Lime Green" then
			frame1.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
		elseif ColorTable[1] == "Maroon" then
			frame1.BackgroundColor3 = Color3.fromRGB(117, 0, 0)
		elseif ColorTable[1] == "Cyan" then
			frame1.BackgroundColor3 = Color3.fromRGB(4, 175, 236)
		elseif ColorTable[1] == "Pastel Green" then
			frame1.BackgroundColor3 = Color3.fromRGB(204, 255, 204)
		elseif ColorTable[1] == "Pink" then
			frame1.BackgroundColor3 = Color3.fromRGB(255, 102, 204)
		elseif ColorTable[1] == "New Yeller" then
			frame1.BackgroundColor3 = Color3.fromRGB(255, 255, 0)
		elseif ColorTable[1] == "Carnation Pink" then
			frame1.BackgroundColor3 = Color3.fromRGB(255, 152, 220)
		elseif ColorTable[1] == "Ghost Grey" then
			frame1.BackgroundColor3 = Color3.fromRGB(202, 203, 209)
		end
	end
end)

but then it doesn’t want to work for the second frame and the second table index ColorTable[2]

I also noticed when you pass the table to the client and the round is over wich means its the second round it still has the table from the first round :confused: