Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

User Input Service script not working properly?

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.

1 answer

✓ Accepted answer

Ok, I think you got a bit mixed up with UIS.

  1. Make sure you're using a localscript! Very important as UIS only runs on the client

  2. The InputBegan event gives two parameters, the input and the game processed event, not the player. Just get the player through game.Players.LocalPlayer

  3. 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

1 comment

0

your truly the best.

This discussion is preserved as it was. New answers, comments, and votes are closed.