How to send send local data to a server module script?

Hello, I am making a building / placement system that includes electronics of all kinds, and now I started work on an elevator which you can input the values of how far in the x,y,z you want it to go using textboxes.
However a textbox requires a script on the client for it to work, and there is no possible way to get its text without using remote events (from my knowledge), and I am really having trouble figuring out how I can do this.

Here is the main server script module, whenever the GotInput:FireServer() fires, it fires to every single elevator that exists in the game and I only want it to send to the elevator that has the matching textbox input thing.

function Electronics.MultiFloorElevator(Elevator,LogisticPorts)
	
	local GotInput = ReplicatedStorage.RemoteEvents.GotInput -- this event will detect when an input box gets, well, an input
	
	task.wait(0.5)
	GotInput:FireAllClients(Elevator)

	GotInput.OnServerEvent:Connect(function(plr,XYZ_Input,matchingPort)
		local x,y,z = table.unpack(XYZ_Input)

		print(x,y,z,matchingPort)
	end)

end
Here is my client script, I need to somehow send the data from GotInput:FireServer() to the specific model that it has been inputted into.
GotInput.OnClientEvent:Connect(function(Model)
	
	if Model.Name == 'MultiFloorElevator' then
		
		-- messy chunk of code, ignore, irrelevant, only takes up space, checks for textboxes
		for _,inputBox : TextBox in pairs(Model:GetDescendants()) do
			if inputBox:IsA('TextBox') then
				inputBox.FocusLost:Connect(function(enterPressed)
					
					local text = inputBox.Text
					
					text:gsub(" ", "")
					local x, y, z = table.unpack(string.split(text, ","))
					
					local matchingPort = Model:FindFirstChild('LogisticPort' .. string.gsub(inputBox.Name, "%D", ""))
					
					-- if value is nil or player didn't input, then just set to 0

					if enterPressed then
						
						GotInput:FireServer({x or 0, y or 0, z or 0},matchingPort)
					end
				end)
			end
		end

	end
end)

Its probably not relevant but here is how the elevator looks like
image
The player inputs stuff into the Move by: boxes, and I need to send that data to the appropriate script for this

1 Like

To be honest. I don’t quite understand what the issue is. What specifically about it isn’t working?

Can you make a remote event inside each elevator that is attached to a serverScript that updates a text value or something inside the elevator when a client changes it so that whatever script you’re using on the server doesn’t have to ask the client about it and instead can look up what the value is?

1 Like

I did try putting a remote event in each elevator one time with a local script but that only worked on the first default model of the elevator in ReplicatedStorage, and no matter what I did it could not work in the model or detect when it had been placed. Its just that when GotInput:FireServer() fires on the client, it fires for every elevator instead of an individual and that is the main issue I am having.

edit: I will be able to reply tomorrow

Would a remote function work for this? I really don’t know how to go about this without making every elevator in the game receive the GotInput at once.

A remote function is exactly the same as a remote event except it waits for the value to return. I prefer remote events because they can do the same things with more control.

You can give each elevator its own remote event instead of trying to share one in the server. That way any message sent through that remote is meant for that elevator. Though sharing a single remote is possible so long as you have a way for the scripts to agree on the elevator (I can’t remember if you can’t directly pass an object reference through)

I figured out a way to do it somehow on my own and I can’t really close the topic so I will use this comment to do it

1 Like

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