Server-Side UserInputService

I hope this message finds you well. I am currently in the process of developing a game that involves intricate features such as headlights and signal lights for vehicles. In pursuit of achieving this functionality, I have encountered an obstacle regarding the utilization of the UserInputService within the server environment.

Despite my efforts, I have been unable to resolve this matter independently. Therefore, I am reaching out to seek your expertise and assistance in addressing this issue. Any guidance or insights you could provide regarding the proper implementation of the UserInputService in a server context would be immensely appreciated.

Thank you for your attention to this matter. I am eager to hear from you and am hopeful for a prompt resolution.

UserInputService is Client-sided. You can use RemoteEvents to send information to the server

1 Like

But what service do I need to use to get the players keyboard moves and the input i received?

UserInputService. Player Movement is based of the humanoid, no service really needed for that

I have an idea, we can create a remote event and put it in a replicated storage and name it like “Event_PlayerID” and whenever we get return from UserInputService we can fire that or we can add a tag.

If you add a tag using a LocalScript, the server won’t see the tag due to how replication works. I recommend you read this to learn more about how client-server communication works in Roblox:

No, no need for that!

Here are some quick steps to let the server know when a player has pressed a button:

Server

local remoteEvent = game:GetService("ReplicatedStorage").YourRemoteEvent
remoteEvent.OnServerEvent:Connect(function(player, key)
    print("Player name: "..player.Name)
    print("Keycode:", key.KeyCode)

    -- your code here...
end)

Client

local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("YourRemoteEvent")
local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean) 	
    remoteEvent:FireServer(input)
end)

If you want the server to know whenever the player presses any button, this solution will work, but if you’re looking to only know when a player presses a specific button or set of buttons, this will be inefficient and waste memory so add some if statements in the client script.

Here’s some stuff for you to read if you need any more help with RemoteEvents: RemoteEvent | Documentation - Roblox Creator Hub

You’re welcome : )

1 Like

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