Gun firing when unequipped and replaced with new gun

My problem is that, when the gun is firing, it also fires the other gun. Only when 1 of 2 of them are equipped.

Client for both scripts:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Events = ReplicatedStorage:WaitForChild("Events")
local fireEvent = Events:WaitForChild("Fire")

local tool = script.Parent

local Details = tool:WaitForChild("Details")
local crosshair = Details:WaitForChild("Crosshair")
local fireAnim = Details:WaitForChild("Fire")
local idleAnim = Details:WaitForChild("Idle")

local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()

local debounce = false
local hold = false

local fireAnimHandler
local idleAnimHandler

function Equipped()
	idleAnimHandler = char.Humanoid.Animator:LoadAnimation(idleAnim)
	idleAnimHandler:Play()
	mouse.Icon = crosshair.Value
end

function Activated()
	if not debounce and tool.Parent == char then
		fireAnimHandler = char.Humanoid.Animator:LoadAnimation(fireAnim)
		fireAnimHandler:Play()
		fireEvent:FireServer(mouse.Hit.LookVector)
		debounce = true
		task.wait(.47)
		debounce = false
	end
end

function Unequipped()
	hold = false
	mouse.Icon = "rbxasset://textures/ArrowFarCursor.png"
	if idleAnimHandler or fireAnimHandler then
		idleAnimHandler:Stop()
		if fireAnimHandler then
			fireAnimHandler:Stop()
		end
	end
end

tool.Equipped:Connect(Equipped)
tool.Activated:Connect(Activated)
tool.Unequipped:Connect(Unequipped)

Server for both scripts:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Events = ReplicatedStorage:WaitForChild("Events")
local fireEvent = Events:WaitForChild("Fire")

local Bullet = ReplicatedStorage:WaitForChild("Bullet")

local tool = script.Parent

fireEvent.OnServerEvent:Connect(function(plr,lookVector)
	--if tool.Parent == (plr.Character or plr.CharacterAdded:Wait()) then
		local bulletClone = Bullet:Clone()
		bulletClone.CFrame = CFrame.new(script.Parent.MuzzleFlash.Position, (lookVector))
		local bodyVelocity = Instance.new("BodyVelocity")
		bodyVelocity.Velocity = lookVector*200
		bodyVelocity.Parent = bulletClone
		bulletClone.CanCollide = false

		bulletClone.Parent = workspace

		task.spawn(function()
			tool.Details.FireSound:Play()
			tool.MuzzleFlash.MuzzleEffect.Enabled = true
			tool.MuzzleFlash.PointLight.Enabled = true
			task.wait(0.05)
			tool.MuzzleFlash.MuzzleEffect.Enabled = false
			tool.MuzzleFlash.PointLight.Enabled = false
		end)
		bulletClone.Touched:Connect(function(hit)
			if hit.Parent.Name ~= plr.Name and hit.Parent:FindFirstChildOfClass("Humanoid") then
				if hit.Name == "Head" then
					hit.Parent.Humanoid:TakeDamage(100)
				else
					hit.Parent.Humanoid:TakeDamage(30)
				end
				bulletClone:Destroy()
			end
		end)
	--end
end)

try test printing Activated, since that is where the issue is

print debounce and Tool.Parent.Name

It was just printing (false or true depending on cooldown) and my name.

was it printing twice though on the second attempt?

perhaps have a bool called “Equipped”

local Equipped = false

and change it to true when equipping, false when uneqipping

then on activation, check if equipped true?

It should already be working rn since you check that when you check the parent being char…

somehow it still thinks its parented under char… even when not…

Please use brackets, even when it doesn’t look like it needs to have brackets. It even says in the official Lua documentation to use excess brackets if you feel like you need to.
The if statement should be:

if (not debounce) and (tool.Parent == char) then

Here’s the bit where it says so, if you were wondering (It’s at the bottom):
https://www.lua.org/pil/3.5.html

Just from a quick glance, whenever you call :FireServer(), you’re not adding any way of specifying which gun should be fired, so it just fires both. There are a couple ways of solving this and I’ll let you decide which you wanna do:

  • Put a RemoteEvent inside of the guns themselves as opposed to ReplicatedStorage and listen/fire those instead
  • Reconnect and Disconnect the OnServerEvent whenever the weapon is Equipped/Unequipped respectively
  • Use the given plr variable to get the character, that is then used to get the equipped weapon
  • (Very not recommended) Pass the gun tool instance as a parameter through the RemoteEvent and use that directly as the one to shoot