Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do we send a UserInput argument through a Remote Event?

Ok so I have two scripts for this, the first one is a local script in the players starterGui it fires a remote event called "InputEvent"

local UIS = game:GetService("UserInputService")
function OnInput(Input)
   script.Parent.InputEvent:FireServer(2)
end
UIS.InputBegan:connect(OnInput)

This should, connect a Input from the UserInput service and then fire the server with the input two a second script.


local Player
local Connection
function ProInput(ip)
	print(ip)
	if ip.UserInputType == Enum.UserInputType.MouseButton2 then
		print("You clicked")
	end
end
 Player.PlayerGui.InputEvent.OnServerEvent:connect(ProInput)

When I test it and I do anything with the mouse or keyboard it first prints: Player1 and then says that UserInputType is not a valid member of Player1(which is me in studio). I'm assuming that through the event it gets changed, but how do I fix this

1 answer

✓ Accepted answer

When you use events in the server, its first parameter will always be the player. So, you would always have to put player before any other parameters in the function in the server, like so: Event.OnServerEvent:connect(function(plyr,ip)

Also, there is another problem in your script. 2 is a number, not an input.

In your server script, your basically doing 2.UserInputType. You can easily fix this by changing the two in the localscript to the input, which in your case is Input, script.Parent.InputEvent:FireServer(Input)

1 comment

0

Thanks a lot, it worked.

This discussion is preserved as it was. New answers, comments, and votes are closed.