Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Breaks when I unequip?

--[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

✓ Accepted answer

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()

This discussion is preserved as it was. New answers, comments, and votes are closed.