How would I send array information using remote events?

I’ve been trying to get this right for some time, but, whenever my current scripting setup gets called through the server, it spits out nil, despite having values to back it. I’m new to scripting, so this is probably a trivial oversight, but, I’ve been having difficulties with this.

Localscript code that sends information through from locascript to serverscript

localPlayer:GetPropertyChangedSignal("Team"):Connect(function()
	for i, value in pairs(TeamArray) do
		if localPlayer.TeamColor == TeamArray[1] then
		iconEvent:FireServer(TeamArray[1], iconImageArray[1])

Server script simply to attempt to send data through, but returning nil apart from player

local function iconSwitch(player, TeamArray[1], iconImageArray[1])
print(TeamArray[1], iconImageArray[1])

end

I am unsure what you mean since your only sending the 1st element of the array, but

local function iconSwitch(player, TeamArray[1], iconImageArray[1])

has incorect syntax
instead it should be like

local function iconSwitch(player, team, iconImage)
    print(team, iconImage)
end

Here are the arrays that are present

local iconImageArray = {
	"rbxassetid://18413761813", 
	"rbxassetid://18413212927", 
	"rbxassetid://18413991987",
	"rbxassetid://18414227286",
	"rbxassetid://18414094164"}
local TeamArray = {
	BrickColor.new("Royal purple"), 
	BrickColor.new("Bright red"), 
	BrickColor.new("Dark green"),
	BrickColor.new("White"),
	BrickColor.new("Electric blue"),
	BrickColor.new("Black"),}

i had an idea where i don’t necessarily need to send array information, simply sending numbers should work for what i wish to achieve

If you wanted to, you could just send the entire array through the remote event
iconEvent:FireServer(TeamArray, iconImageArray)

and did you connect the iconSwitch function to the iconEvent.onClientEvent

yup, it has been connected
image

they return as nil when i tried to send the arrays
image

It isn’t connected to the correct event.
Instead, it should be connected to
iconEvent.OnClientEvent:Connect(iconSwitch)

I presume you meant OnServerEvent instead of OnClientEvent right?

Yeah you are right! i totally forgot about that. Does it work though with OnServerEvent?

it seemingly did!

image

1 Like

for some reason, it sends a whole lot of times…

Are you changing the player’s team alot of times?

nope, only once. However, it might be an issue due to how I have formatted my serverscript.
image

it sends it 6 times for whatever the reason may be,…
image

Try put iconEvent:FireServer(TeamArray, iconImageArrray) outside of the for loop

1 Like

yup! it now only sends once. Thank you.

1 Like

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