01 | Player = game.Players.LocalPlayer |
02 | local tool = Instance.new( "Tool" ) |
03 | tool.Parent = Player.Backpack |
04 | local mouse = Player:GetMouse() |
05 | tool.Name = "SOMETHING" |
06 | local tool 2 = Instance.new( "Part" , tool) |
07 |
08 | tool 2. Transparency = 1 |
09 | tool 2. Name = "Handle" |
10 |
11 | tool.Selected:connect( function () |
12 | mouse.KeyDown:connect( function (key) |
13 | if key = = "z" then |
14 | print ( "TESTING" ) |
15 | end |
16 | end ) |
17 | end ) |
How do I make it so when I un-equip the tool and then I press Z, nothing will happen?
Every tool has these functions:
Equipped ( mouse object )
Unequipped
So, I would recommend making a function that you can connect/disconnect
whenever the player equips/unequipped the tool, E.G:
1 | function printText() |
2 | print ("Player joined the game.) |
3 | end |
4 |
5 | local func = game.Players.PlayerAdded:connect(printText) -- does the function |
6 |
7 | func:disconnect() -- stops it from working again |
So:
01 | Player = game.Players.LocalPlayer |
02 | local tool = Instance.new( "Tool" ) |
03 | tool.Parent = Player.Backpack |
04 | local mouse = Player:GetMouse() |
05 | tool.Name = "SOMETHING" |
06 | local tool 2 = Instance.new( "Part" , tool) |
07 |
08 | tool 2. Transparency = 1 |
09 | tool 2. Name = "Handle" |
10 |
11 | function attack(key) |
12 | key = key:lower() -- very important, use this every time you check for a lowercase letter |
13 | if key = = "z" then -- use tab for formatting, not spaces |
14 | print ( "TESTING" ) |
15 | end |
Hopefully this works. If not, just use a debounce
.