Hi, I’m making a module but I’m having a thought, is it possible to get the players input on a server-sided script? I won’t be surprise if this is impossible and I’m not a beginner so if this is impossible I could find a way around it but if it’s possible, it would make making that module much easier. Any help would be appreciated.
No, players input is client sided. You would need to use an remote event to send the input to the server.
3 Likes
uh no, the server doesnt have a keyboard.
sample script to kick a player when they press Z (uses a remoteEvent named “KickPlayer” in repl storage):
--LocalScript in StarterPlayer > StarterPlayerScripts
local uis = game:GetService("UserInputService")
local isInChat = false
uis.TextBoxFocused:Connect(function()
isInChat = true
end)
uis.TextBoxFocusEnded:Connect(function()
isInChat = false
end)
uis.InputBegan:Connect(function(inp)
if inp.KeyCode == Enum.KeyCode.Z and isInChat == false then
game.ReplicatedStorage.KickPlayer:FireServer()
end
end)
--Script in ServerScriptService
game.ReplicatedStorage.OnServerEvent:Connect(function(plr) plr:Kick("Told ya don't press Z!") end)