Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Breaks when I unequip?

Asked by
A9X 10
9 years ago
--[Variables

tool = Instance.new("Tool")
handle = Instance.new("Part")
debounce = false

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

--[Program

tool.Name = "Codec"
tool.Parent = player.Backpack

handle.Transparency = 1
handle.Name = "Handle"
handle.Parent = tool

tool.Equipped:connect(function()
    if handle and tool then
        print("Resuming execution")
        wait()
    end
    mouse.KeyDown:connect(function(key)
        if debounce == true then return end
        debounce = true
        if key == "z" then
            print("Testing")
            wait(2)
            debounce = false
        end
    end)
end)

When I equip it for the first time and press Z, it works fine. But then when I de equip it, equip it again, and press Z, it does nothing. Anyone know why?

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

You're connecting to KeyDown every time the tool is equipped. You already have the player mouse, you aren't using the tool mouse. Connect to KeyDown outside of the Equipped event and make sure the tool is equipped before doing anything, or, use the tool's mouse instead of the player mouse.

tool.Equipped:connect(function(mouse)

instead of mouse=player:GetMouse()

Ad

Answer this question