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?
local UserInputService = game:GetService("UserInputService") local tool = script.Parent local function onInputBegan(input,gameProcessed) tool.Equipped:Connect(function() if input.KeyCode == Enum.KeyCode.F then print("it worked.") end end) end 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:
local UserInputService = game:GetService("UserInputService") local tool = script.Parent local equipped = false tool.Equipped:Connect(function() equipped = true end tool.Unequipped:Connect(function() equipped = false end UserInputService.InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.F and equipped == true then --Do stuff end end)