Parameter not passing properly?

I have a remote event being called.

game.ReplicatedStorage.PersonaRemoteEvents:FindFirstChild(persona):FindFirstChild(action):FireServer(icon)

I later connect several remote events (you can see with the variables that I’m trying to do this abstractly to make it as automated as I can) with a for loop:

for i, move in pairs(moveList) do
		move.OnServerEvent:Connect(function(plr, icon)

			-- Check if the cooldown is up for the move and make sure the player isn't dead
			if cooldowns.Check(plr, move.Name) and plr.Character.Humanoid.Health > 0 then
				
				print(icon) -- TODO: why is this nil? I'm passing it in??

				-- Call the move and tick the cooldown
				cooldowns.Down(plr, "notPersonaActive")
				cooldowns.Start(plr, move.Name, cdList[move.Name].length, icon) -- Start cooldown first because the task.spawn() lets it run while the yielding move function runs
				moveFunctions[move.Name](plr) -- No task.spawn() so that active is set properly as it has to wait for the move to finish
				cooldowns.Up(plr, "notPersonaActive")



			end

		end)	
	end

For some reason, even though I am passing the icon through the remote event, when it gets to the print() statement for testing, I just get nil.
Some important things to note:

  • Everything else works. The remote events, the connections, the calling, they all work. It’s this one thing that is weird.
  • I tried adding another random parameter and printing it, just a string “e”. This works fine.
  • When I print the full name of the object right before calling the remote event, it prints the full name perfectly fine.
  • The “icon” being passed in is a locally created GUI object, a frame to be specific.

Why isn’t it working? How do I fix it?

EDIT: It seems the problem may be that passing the locally created object as a parameter gives it by reference, meaning the server still can’t access it. Having identified this problem, I’m still not sure of an efficient way to fix it, so if anyone knows, please share.

1 Like

How do you know icon exists when you send it?

You need to print it before you send through the Remote to make sure it is there to be sent.

1 Like

I did this.

On another note, I think I know why it isn’t working. Still don’t know how to fix it though, so I’ll edit the post.

Oh, a " locally created object”.

Yes, that is the problem. The server will never recognize a " locally created object”.

3 Likes

Is there any way to work around this?

Can you explain exactly in steps like 1. 2. 3. for what your doing and what its for lets come up with a solution right now !

Is there a specific reason you absolutely need it on client only?

Because, if it is just an icon, you could put it in ReplicatedStorage and get it from there in server side… or use a RemoteFunction to create the icon on the server, then send it back to the client, so it ensure it exist for both client and server.