local UIS = game:GetService("UserInputService") local tool = script.Parent local function OnInputBegan(input, player) if input.UserInputType == Enum.UserInputType.E then tool:Clone().Parent = player.Backpack print("E was pressed") end end UIS.InputBegan:Connect(OnInputBegan)
Code does not work when I press E, it also does not go into the player's backpack.
Ok, I think you got a bit mixed up with UIS.
Make sure you're using a localscript! Very important as UIS only runs on the client
The InputBegan event gives two parameters, the input and the game processed event, not the player. Just get the player through game.Players.LocalPlayer
UserInputType detects what type of input the player is using, such as keyboard, mouse, touchscreen, etc. To sense if the user is pressing a specific key, change the UserInputType you're checking for to keyboard, then add the following code inside:
if input.KeyCode == Enum.KeyCode.E then --E is pressed end
This should work:
local UIS = game:GetService("UserInputService") local tool = script.Parent local function OnInputBegan(input, GPE) if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.E then tool:Clone().Parent = player.Backpack print("E was pressed") end end end UIS.InputBegan:Connect(OnInputBegan)
Hopefully this helps