so i have a tool in the starterpack, and within this tool there is a localscript.
so im trying to make it so that you can ONLY activate this key function when the tool is equipped, but the script seems to not run. if there is a bug, what could it be?
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 | local tool = script.Parent |
03 |
04 | local function onInputBegan(input,gameProcessed) |
05 |
06 | tool.Equipped:Connect( function () |
07 | if input.KeyCode = = Enum.KeyCode.F then |
08 |
09 | print ( "it worked." ) |
10 |
11 | end |
12 |
13 | end ) |
14 | end |
15 | UserInputService.InputBegan:connect(onInputBegan) |
Just have a variable that tells whether the tool is equipped that changes whenever it's equipped and unequipped. Here's an example:
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 | local tool = script.Parent |
03 |
04 | local equipped = false |
05 |
06 | tool.Equipped:Connect( function () |
07 | equipped = true |
08 | end |
09 |
10 | tool.Unequipped:Connect( function () |
11 | equipped = false |
12 | end |
13 |
14 | UserInputService.InputBegan:Connect( function (key) |
15 | if key.KeyCode = = Enum.KeyCode.F and equipped = = true then |
16 | --Do stuff |
17 | end |
18 | end ) |