Hello I would like to make a skill for a game only work when the tool is equipped so I wrote the following script for example and it's not working. Any ideas on how to fix it ?
local uis = game:GetService('UserInputService') local plr = game.Players.LocalPlayer script.Disabled = false script.Parent.Equipped:connect(function() script.Disabled = false uis.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.E then print('The tool was equipped') end end) end) script.Parent.Unequipped:connect(function() script.Disabled = true uis.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.E then print('The tool was unequipped') end end) end)
Okay firstly.. you can't mess with the script's Disabled
property.
I suggest making an a variable true when you equip, and simply checking it upon key press.
local uis = game:GetService('UserInputService') local plr = game.Players.LocalPlayer local eq = false --Equipped variable script.Parent.Equipped:Connect(function() --'connect' is deprecated eq = true; --set equipped variable to true script.Parent.Unequipped:Wait(); --wait for them to unequip eq = false; --set equipped variable to false end) uis.InputBegan:Connect(function(input,process) if not process then --Make sure they're not chatting if input.KeyCode == Enum.KeyCode.E then --check equipped val print(eq and "The tool is equipped" or "The tool is unequipped"); end end end)