Remote Events and Inputs

The Goal: I’m trying to detect the input from a local script and send it over to a server script via a remote event to be later looked at.
Specifically, I want to see what type of input it is, what key was pressed, etc. and I want to do all this within the server script

The Issue: Whenever I press an input, I get an error in the output attempt to index nil with ‘UserInputType’

What I’ve tried: I have tried a lot. the only thing I remember specifically is redefining variables within the function before passing the variable off.

Local Script:

--//Functions
function movementFire(input)
	print(input)
	print(input.KeyCode)
	print(input.UserInputType)
	inputRemote:FireServer(input) --//this is defined earlier in the script
end

--//Event Listeners
UIS.InputBegan:connect(movementFire)

Side note - The print functions all produce an output at this stage

Server Script:

--//Functions
function inputCipher(player, input)
	print(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		print("Was Keyboard")
	end
end

--//Event Listeners
inputRemote.OnServerEvent:connect(inputCipher) --//this is defined earlier in the script

Side note - at this point, the server-side print function returns nil and then gives me the error the next line

I’m really confused needless to say.
Is it just not possible to transport inputs through remote events?

Thanks in advance for any help

On the local script is the 2nd and 3rd print correct?

Im pretty sure roblox just wont replicate that datatype to the server
Youll prob have to just get the desired info on the client and then transfer the actual values to the server
Like:
:FireServer(input.UserInputType.Keyboard)

3 Likes

Well… it’s funny how the solutions are always right under our noses. This ended up working perfectly.

If you’re curious, or for anyone who finds this in the future, the new script reads

Local Script:

--//Functions
function movementFire(input)
	print(input)
	print(input.KeyCode)
	print(input.UserInputType)
	
	local inputType = input.UserInputType
	local inputButton = input.KeyCode
	
	inputRemote:FireServer(inputType, inputButton)
end

--//Event Listeners
UIS.InputBegan:connect(movementFire)

Server Script:

--//Functions
function inputCipher(player, inputType, inputButton)
	print(inputType)
	if inputType == Enum.UserInputType.Keyboard then
		print("Was Keyboard")
	end
end

--//Event Listeners
inputRemote.OnServerEvent:connect(inputCipher)
2 Likes