Help with tool printing without being equipped

Hello people!,
I have this local Script and script here I have set it up so that when the tool is equipped and the player clicks it is suppose to Fire a remote event and to print “a” but I have this problem where by when I unequipped it still prints “a”
here is the local script

local Lp = game.Players.LocalPlayer
local Mouse = Lp:GetMouse()
local Tool = script.Parent
local Fire = Tool.Fire
local Shoot = true

Tool.Equipped:Connect(function()
    Mouse.Button1Up:Connect(function()
            Fire:FireServer()
            wait(1)
    end)
end)

here is the normal script

local Tool = script.Parent
local Fire = Tool.Fire

Fire.OnServerEvent:Connect(function(plr)
    if Tool.Equipped then
            print("a")
    end
end)

any help is appreciated!

You’ll have to disconnect your established connection. When you put the tool away, the Button1Up connection is still running in the background.

local Lp = game.Players.LocalPlayer
local Mouse = Lp:GetMouse()
local Tool = script.Parent
local Fire = Tool.Fire
local Shoot = true
local ButtonConnection 

Tool.Equipped:Connect(function()
   ButtonConnection = Mouse.Button1Up:Connect(function()
            Fire:FireServer()
            wait(1)
    end)
end)

Tool.Unequipped:Connect(function()
	if typeof(ButtonConnection) == "RBXScriptConnection" then --Makes sure it's a connection before attempting to disconnect it.
		ButtonConnection:Disconnect()
	end
end)
2 Likes

Thanks this actually worked
i appreciate it

1 Like