Userinputservice is not working like its suppose to

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

  1. What do you want to achieve? Keep it simple and clear!
    TO GET THIS TO FLIPPIN WORK
  2. What is the issue? Include screenshots / videos if possible!
    its not printin anything which means if i were to do something as to destory somethin it wouldnt work
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    COULDNT find any
--ServerScript
--Services
local UIS = game:GetService("UserInputService")

--Variables
local Tool = script.Parent
local SC = Tool:WaitForChild("SC")

--Other
SC.OnServerEvent:Connect(function(Player,Key)
    if Key and Key.KeyCode == Enum.KeyCode.F then
        print(Player.Name .. " hit the F key")
    end
end)

--LocalScript
--Services
local UIS = game:GetService("UserInputService")

--Variables
local Tool = script.Parent
local SC = Tool:WaitForChild("SC")

--Other
UIS.InputBegan:Connect(function(Key)
    if Key then 
        if Key.KeyCode == Enum.KeyCode.F then
        SC:FireServer(Enum.KeyCode.F)
       end
    end
end)

Keep in mind this a tool so i dont rlly know why it wont work

You’re sending “Enum.KeyCode.F” to the server instead of the key.

Try

SC:FireServer(Key)

and what about server script would i change anything over there to?

No, you shouldn’t have to. What you have now is being read on the server as:

SC.OnServerEvent:Connect(function(Player,Key)
    if Enum.KeyCode.F and Enum.KeyCode.F.KeyCode == Enum.KeyCode.F then
        print(Player.Name .. " hit the F key")
    end
end)

which obviously makes no sense. But replace this line:

SC:FireServer(Enum.KeyCode.F)

with

SC:FireServer(Key)

and it can be read on the server as:

SC.OnServerEvent:Connect(function(Player,Key)
    if Key and Key.KeyCode == Enum.KeyCode.F then
        print(Player.Name .. " hit the F key")
    end
end)

still aint printin like i told you this is in a tool

can you send a model file or place file

edit:
nvm that ill try replicate it myself

sure thing give me one minute ok hold on

here ya goo000
mkbm.rbxm (4.2 KB)

is it necessary to check whether the player has pressed a key on the server? because it won’t fire the remote anyways unless the key pressed was f.

someone said that the first arg will always be the player so added a 2nd arg

yes that’s fine but I’m talking about this line:

if Key and Key.KeyCode == Enum.KeyCode.F then -- The one on the server script

you don’t really need it because you’ve already checked this on the client. Plus I don’t know if you can pass an inputObject through a remote event which is what’s halting the function from continuing.

UIS is only for Local Scripts. I suggest doing what @Thr3star said.

1 Like

You cannot use UserInputService on the server, My bad you were responding to his post.

keycode not inputobject those different

inputObject is the “Key” object that comes from using the UIS functions. It’s unnecessary to check what key was pressed on the server if you’re only having it activate when you press F anyways.

so i remove the check and it should work because the remote is telling the server that theres already a check?

You print the Input.Keycode to the server

your 2 options are either:

--LocalScript
--Services
local UIS = game:GetService("UserInputService")

--Variables
local Tool = script.Parent
local SC = Tool:WaitForChild("SC")

--Other
UIS.InputBegan:Connect(function(Key)
	if Key then 
		if Key.KeyCode == Enum.KeyCode.F then
		SC:FireServer(Enum.KeyCode.F)
	   end
    end
end)
--ServerScript

--Variables
local Tool = script.Parent
local SC = Tool:WaitForChild("SC")

--Other
SC.OnServerEvent:Connect(function(Player,Key)
	if Key and Key == Enum.KeyCode.F then
		print(Player.Name .. " hit the F key")
	end
end)

^ Which is (in my opinion) weird. OR your other option is this:

if Key then 
		if Key.KeyCode == Enum.KeyCode.F then
		SC:FireServer()
	   end
    end
SC.OnServerEvent:Connect(function(Player)
	print(Player.Name .. " hit the F key")
end)

both work

wait it already picks up everything from the client/localscript?

I believe he wants the server to know what key you pressed instead of printing of what they pressed.