Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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)

0
Thanks a lot, it worked. Wafflecow321 457 — 7y
Ad

Answer this question