Say for example I have a chair, I use seat.occupant and use :GetPlayerFromCharacter
Is there a way I can get userinput from the player this way, or is it limited to only localscripts?
Say for example I have a chair, I use seat.occupant and use :GetPlayerFromCharacter
Is there a way I can get userinput from the player this way, or is it limited to only localscripts?
UserInputService is client-sided but you can link it up to the server with RemoteEvents. The way I usually do it is to check everything on the client, if it matches up with an action, then you fire the event for that and the server does whatever the action is
A single macro will destroy that server. I do hope you have some debounces or cool downs. I activate functions instead of sending input to the server. It’s essentially the same thing, but you should never think of it as sending input to the server. Think of it as activating a function on the server from the client.
Cant an exploiter just skip the client checks and fire the remote?
It is impossible to directly get User Inputs from the server-side. You would have to send data from the client by firing a remote using a LocalScript, with a script hooking itself to said remote.
I probably explained it poorly but yeah, that’s what I’d suggest. Don’t just fire off every input, fire it off whenever it matches up against some action. If you want to, say, print something on the server if the user presses the key ‘Z’, then you’d wait for that key and fire it off whenever that key is pressed
And yeah, like MineDevs said, always make sure you’re verifying it. The client isn’t secure, so assume every action is bad and only do something after you compare it’s good
you can use remote events. Yes, they are limited to local scripts, but the local script can send it to the server.
Why? What are you trying to do? If you need UserInputService from the server-side, you’re doing something wrong. Please state your exact use case so we know what you’re doing and how you can resolve the problem you’re encountering.
I second this. There’s probably another solution to your problem that doesn’t require server-side user input.
UserInputService is client-side, but you could Fire a remote event to make it server side to… for example:
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, GameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
game.ReplicatedStorage.KeyBindEvent:FireServer(input)
end
end)
--server side, also I made the script here not in studio so there might be an error lol
game.ReplicatedStorage.KeyBinEvent.OnServerEvent:Connect(function(plr, input)
if input.KeyCode == Enum.KeyCode.F then
print(plr.Name.." has pressed F key")
elseif input.KeyCode == Enum.KeyCode.R then
print(plr.Name.." has pressed R key")
end
end)
-- this is just an example ;P
I know I could fire remotes, I was just wondering if there was a simpler way such if I had the player.
Thank you for all of the responses though, very helpful for what I need
Input should always be handled by the client. Backend logic should be handled by the server.