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 ?
01 | local uis = game:GetService( 'UserInputService' ) |
02 | local plr = game.Players.LocalPlayer |
03 | script.Disabled = false |
04 |
05 | script.Parent.Equipped:connect( function () |
06 | script.Disabled = false |
07 | uis.InputBegan:Connect( function (input) |
08 | if input.KeyCode = = Enum.KeyCode.E then |
09 | print ( 'The tool was equipped' ) |
10 | end |
11 | end ) |
12 | end ) |
13 |
14 | script.Parent.Unequipped:connect( function () |
15 | script.Disabled = true |
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.
01 | local uis = game:GetService( 'UserInputService' ) |
02 | local plr = game.Players.LocalPlayer |
03 | local eq = false --Equipped variable |
04 |
05 | script.Parent.Equipped:Connect( function () --'connect' is deprecated |
06 | eq = true ; --set equipped variable to true |
07 | script.Parent.Unequipped:Wait(); --wait for them to unequip |
08 | eq = false ; --set equipped variable to false |
09 | end ) |
10 |
11 | uis.InputBegan:Connect( function (input,process) |
12 | if not process then --Make sure they're not chatting |
13 | if input.KeyCode = = Enum.KeyCode.E then |
14 | --check equipped val |
15 | print (eq and "The tool is equipped" or "The tool is unequipped" ); |
16 | end |
17 | end |
18 | end ) |