How to use a UserInputService in a tool?

Hey, so basically i want to have a working inventory system where players can press a button. For example “V” and if the tool is equipped whilst that button is pressed then the tool will be stored in the inventory.

Note: I have a working inventory system all i want help with is making it so when “V” is pressed the parent of set to a folder named Inventory inside of the player.

Currently my script inside the tool is:

local Item = script.Parent
local UserInputService = game:GetService("UserInputService")

local function OnInputBegan(input, Player)
	if input.UserInputType == Enum.KeyCode.V then
		print("Input Worked")
		Item.Parent = Player:FindFirstChild("Inventory")
		end
end

UserInputService.InputBegan:Connect(OnInputBegan)```
1 Like

Just add a line to check if the tool is equipped:

local Item = script.Parent
local UserInputService = game:GetService("UserInputService")

local function OnInputBegan(input, Player)
	if input.UserInputType == Enum.KeyCode.V then
if Player.Character and Player.Character:FindFirstChild("toolname ") then
		print("Input Worked")
		Item.Parent = Player:FindFirstChild("Inventory")
		end
end
end

UserInputService.InputBegan:Connect(OnInputBegan)

i’m on mobile so the formatting might be messed up

The thing is not even the input is being detected.

Hey, did you use a localscript to use UserInputService? If not then it may be the issue.

1 Like

Hey, yeah around 20 minutes ago i began re reading the documentation until i realised it doesnt work in scripts so i have re wrote all of my script to fit for the local version.

Did you manage to make it work? Or you’re still facing an issue?

I have managed to make it work by using remotevents and using it in a local script.

Alright, if I’m right you have to mark the post/ a reply as resolved so everyone is aware that you no longer need help. Have a great day!

I have lol. Check your first message.

I had to update it lol, thank you. Anyway, good luck ^^

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