How to make a script use or imitate UserInputService in server script?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Useing or imitate UserInputService in server script?

  2. What is the issue? Just a question.

  3. What solutions have you tried so far? Chatgpt, google, work arounds, 2 hours of trying something similar that didn’t work.

local tool = script.Parent
local NonEquip = Color3.new(0.266667, 0.278431, 0.294118)
local Equip = Color3.new(0, 0.67451, 0.988235)

local UserInputService = game:GetService("UserInputService")

local function onInputBegan(input, _gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.C then
			if input.UserInputType == Enum.UserInputType.Keyboard then
				if input.KeyCode == Enum.KeyCode.X then
					tool.B.Enabled = false -- resets the script to the start
					tool.V.Enabled = false -- resets the script to the start
					tool.N.Enabled = false -- resets the script to the start
					tool.C.Enabled = false -- resets the script to the start
					wait(5)
					tool.B.Enabled = true -- resets the script to the start
					tool.V.Enabled = true -- resets the script to the start
					tool.N.Enabled = true -- resets the script to the start
					tool.C.Enabled = true -- resets the script to the start
				end
			end
		end
	end
end



UserInputService.InputBegan:Connect(onInputBegan)
1 Like

this isnt possible but you can try with a modulescript. im not sure but it definitely doesnt work on server scripts

also you are using a server script on a tool. i think its best using a localscript for this

1 Like

This is what you should use RemoteEvents for.

3 Likes

You can’t. But what you can do is send the input to the server via RemoteEvent and then handle your logic there.
But looking at your code, you are trying to manipulate UI elements as well, which you can only do on the client side. So maybe try to figure out what you want to do exactly and then split it into client and server code.

A server script can’t access the client’s input, you could use a remote event to pass the key press from a client script to a server script though

Kinda rude to assume I don’t know what I’m doing with the ui, that’s just left over script from my old duplicated script. This script is just one out of 5.

uh i think im seeing this wrong but are you trying to check if one input is C and X at the same time?

I don’t use remoteEvents for any of my games for vulnerability reasons. But thank you.

Didnt notice that my old script had multiple keypresses tho.

then its completely impossible
remote events are the only secure way to communicate between the client and the server
and userinputservice is not creatable (you cant recreate it) and only works on client
try adding security keys or smth that makes it very secure

I was thinking something more like this but for server scripts

local tool = script.Parent
local character = tool.Parent
local player = game.Players:GetPlayerFromCharacter(character)
local mouse = player:GetMouse()

mouse.KeyDown:Connect(function(key)
if key == “e” and tool:IsDescendantOf(player.Backpack) then
print(“Pressed e while tool is equipped”)
end
end)

yeah that only works for local scripts

You can easily prevent this by using server-side validation.

Theres nothing on google, can you link somewhere I can read about this or explain it to me?

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