Why doesn't my remote event send over the image towards the server script?

  1. What do you want to achieve?

Basically, I want to send over the image that has already been found in the local script to the server script through the remote event parameters, however, when I send it over it just says that that the variable ‘image’ is a nil value. Also, the idea is that I want it to be on the server which will allow me to fire all the clients in the game, allowing for the image button to move to a certain position on all of the client’s screens (I hope that makes sense!)

  1. What solutions have you tried so far?

I’ve looked everywhere for the answer the answer and tried multiple solutions, however, this doesn’t seem to work. The ImageButton with which I want to send over has been created during the game, therefore I can’t access the PlayerGui through a server script.

Local script:

for i,v in pairs(game:GetService("Players"):GetPlayers()) do
     for i, image in pairs(player.PlayerGui.typingChallenge.otherRacePosition:GetChildren()) do
	 	if v.Name == image.Name then
			local image = image 	

--Sorry for the incorrect formatting, I've tried to do it the best I can.

Server script:

correctRemoteEvent.OnServerEvent:Connect(function(player, image)

The server script is where the issue occurs, whenever I try to print the parent of the image it says the error that the image doesn’t even exist, even though I’ve just passed it through. Also, the for loop in the local script code simply just find the correct image (Which works)

Thanks for anyone who helps me, that is much appreciated, Feel free to ask any questions and I’ll accept your answer if it works. :slight_smile:

You can’t send a reference of an Instance to the server if it doesn’t exist there. This is a case of the XY Problem - where you’re trying to solve an issue with a pre-selected (and flawed) solution to the problem instead of describing the original problem to allow better solutions to be presented.

Can you explain what you are actually trying to do - as in why does the server need the image Instance? Would it perhaps make more sense to send over the asset ID of the image and then use it for something on the server? We need to know the real problem you’re trying to solve to be able to provide alternatives.

I’ll add this to my actual question in a sec, but I’m trying to get the image onto the server which will then fire all the clients on the game to move it a certain amount (Which has already been preset)

If the imagebutton has been created independently by each client, then the Instance isn’t common and one person’s image button does not exist on anyone else’s client. Instead, you should send some sort of identifier.

For example, if you know every client will have named the image “ImageA” then you would send the string ‘ImageA’ to the server, and fire all clients with that identifier and then they can all do whatever it is you want them to do with the imagebutton that matched that identifier/name.

Oh that makes sense, so instead of finding the imageButton and sending it to the server, I can just send over a variable name of the imageButton and when firing all clients it can find each of the imageButton’s individually on each client? Sorry if that doesn’t make much sense.

Yeah exactly, so develop some sort of naming convention that is predictable and will be the same for every player.

Even if that’s as simple as Image1, Image2, Image3, Image4, that’s fine as long as Image1 for player1 is the same one as Image1 for player2.

correctRemoteEvent:FireServer( image.Name )

And the server:

correctRemoteEvent.OnServerEvent:Connect( function( player, imageName )
	correctRemoteEvent:FireAllClients( imageName )
end )

And back on the client again:

correctRemoteEvent.OnClientEvent:Connect( function( imageName )
    local image = player.PlayerGui.typingChallenge.otherRacePosition:FindFirstChild( imageName )
    -- todo stuff here on each client
end )
1 Like

Didn’t even think of doing that, not sure why, thanks for the help! I’ve accepted your answer.

1 Like