When 2 guns have been equipped something weird occurs?

I made a simple gun script that casts a ray to the players mouse’s position when they click, so Instead of it being semi-automatic I figured I would make a fully-automatic gun. So I duplicated the first gun and tweaked a few things so that when the player is holding down their mouse it rapidly fires. But when I switch from gun to gun it’s like the semi automatic one takes the script from the fully automatic one and uses that instead. I find this very weird and I’ve done everything I could think of from making independent remote events, to renaming almost everything in each model. If any of this is unclear which I’d suppose it is, please tell me what you’re confused about as I would like for this to be fixed. Thanks!

Semi-Auto gun’s localscript inside of the tool:

local tool = script.Parent
local GunModel = tool:WaitForChild("Gun")
local origin = GunModel:WaitForChild("Barrel")

local GunShot = tool:WaitForChild("GunShot")
local HitMarker = tool:WaitForChild("HitMarker")
local ReloadindSound = tool:WaitForChild("Reloading")

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Ammo = tool:WaitForChild("Ammo")
local MaxAmmo = tool:WaitForChild("MaxAmmo")
local Reloading = false

Mouse.TargetFilter = tool.Gun
Mouse.TargetFilter = Player.Character

tool.Equipped:Connect(function()
	local GunGui = tool.GunGui:Clone()
	GunGui.Parent = Player.PlayerGui
	
	GunGui.AmmoLabel.Text = "Ammo: "..Ammo.Value.."/"..MaxAmmo.Value
	
	UIS.InputBegan:Connect(function(input)
		if input.KeyCode == Enum.KeyCode.R and Ammo.Value ~= MaxAmmo.Value and Reloading == false then
			Reloading = true
			ReloadindSound:Play()
			wait(1.33)
			Ammo.Value = MaxAmmo.Value
			Player.PlayerGui.GunGui.AmmoLabel.Text = "Ammo: "..Ammo.Value.."/"..MaxAmmo.Value
			Reloading = false
		end
	end)
end)

tool.Unequipped:Connect(function()
	if Player.PlayerGui.GunGui then
		Player.PlayerGui.GunGui:Destroy()
	end
end)

local debounce = false
tool.Activated:Connect(function()
	local recoil = Player.Character.Humanoid:LoadAnimation(script.Parent.Recoil)
	if debounce == false and Ammo.Value ~= 0 and Reloading == false then
		debounce = true
		local BarrelPos = script.Parent.Gun.Barrel.Position
		local MousePos = Mouse.Hit.p
		game.ReplicatedStorage.OnShoot:FireServer(MousePos, BarrelPos, GunShot)
		Ammo.Value = Ammo.Value -1
		Player.PlayerGui.GunGui.AmmoLabel.Text = "Ammo: "..Ammo.Value.."/"..MaxAmmo.Value
		recoil:Play()
		wait(0.5)
		debounce = false
	end
end)

game.ReplicatedStorage.OnHitPlayer.OnClientEvent:Connect(function()
	HitMarker:Play()
end)

Fully auto guns localscript inside of the tool:

local ARtool = script.Parent
local GunModel = ARtool:WaitForChild("ARGun")
local origin = GunModel:WaitForChild("Barrel")

local GunShot = ARtool:WaitForChild("GunShot")
local HitMarker = ARtool:WaitForChild("HitMarker")
local ReloadindSound = ARtool:WaitForChild("Reloading")

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Ammo = ARtool:WaitForChild("Ammo")
local MaxAmmo = ARtool:WaitForChild("MaxAmmo")
local Reloading = false
local Held = ARtool.Held
Held.Value = false

Mouse.TargetFilter = ARtool.ARGun
Mouse.TargetFilter = Player.Character

ARtool.Equipped:Connect(function()
	local GunGui = ARtool.GunGui:Clone()
	GunGui.Parent = Player.PlayerGui
	
	GunGui.AmmoLabel.Text = "Ammo: "..Ammo.Value.."/"..MaxAmmo.Value
	
	UIS.InputBegan:Connect(function(input)
		if input.KeyCode == Enum.KeyCode.R and Ammo.Value ~= MaxAmmo.Value and Reloading == false then
			Reloading = true
			ReloadindSound:Play()
			wait(1.33)
			Ammo.Value = MaxAmmo.Value
			Player.PlayerGui.GunGui.AmmoLabel.Text = "Ammo: "..Ammo.Value.."/"..MaxAmmo.Value
			Reloading = false
		end
	end)
end)

ARtool.Unequipped:Connect(function()
	if Player.PlayerGui.GunGui then
		Player.PlayerGui.GunGui:Destroy()
		Held.Value = false
	end
end)

local debounce = false

ARtool.Equipped:Connect(function()
	UIS.InputBegan:Connect(function(inputObject)
		if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
			Held.Value = true
			local recoil = Player.Character.Humanoid:LoadAnimation(script.Parent.Recoil)
			if debounce == false and Ammo.Value ~= 0 and Reloading == false then
				while Held.Value == true do
					print("Shot")
					debounce = true
					local BarrelPos = script.Parent.ARGun.Barrel.Position
					local MousePos = Mouse.Hit.p
					game.ReplicatedStorage.OnARShoot:FireServer(MousePos, BarrelPos, GunShot)
					Ammo.Value = Ammo.Value -1
					Player.PlayerGui.GunGui.AmmoLabel.Text = "Ammo: "..Ammo.Value.."/"..MaxAmmo.Value
					recoil:Play()
					wait(0.1)
					debounce = false
				end
			end
		end
	end)
	
	UIS.InputEnded:Connect(function(inputObject)
		if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
			Held.Value = false
		end
	end)
end)

game.ReplicatedStorage.OnHitPlayer.OnClientEvent:Connect(function()
	HitMarker:Play()
end)

Server script:

local debris = game:GetService("Debris")
local Range = 250
	
local function CreateBeam(origin, direction)
	local midPoint = (origin + direction)/2
		
	local Bullet = Instance.new("Part", workspace)
	Bullet.Anchored = true
	Bullet.CanCollide = false
	
	Bullet.CFrame = CFrame.new(midPoint, origin)
	Bullet.Size = Vector3.new(0.5,0.5, direction.magnitude)
	
	debris:AddItem(Bullet,0.1)
end

game.ReplicatedStorage.OnShoot.OnServerEvent:Connect(function(player, MousePos, OriginPos, GunShot)
	local direction = (MousePos - OriginPos).Unit * Range
	
	local bulletRay = workspace:Raycast(OriginPos, direction)
	
	GunShot:Play()
	
	if bulletRay then
		local character = bulletRay.Instance.Parent
		
		if character:FindFirstChild("Humanoid") then
			local humanoid = character.Humanoid
			
			if humanoid and humanoid ~= player.Character.Humanoid then
				humanoid:TakeDamage(25)
				game.ReplicatedStorage.OnHitPlayer:FireClient(player)
			end
		end
	end
end)

game.ReplicatedStorage.OnARShoot.OnServerEvent:Connect(function(player, MousePos, OriginPos, GunShot)
	local direction = (MousePos - OriginPos).Unit * Range
	
	local bulletRay = workspace:Raycast(OriginPos, direction)
	
	GunShot:Play()
	
	if bulletRay then
		local character = bulletRay.Instance.Parent
		
		if character:FindFirstChild("Humanoid") then
			local humanoid = character.Humanoid
			
			if humanoid and humanoid ~= player.Character.Humanoid then
				humanoid:TakeDamage(25)
				game.ReplicatedStorage.OnHitPlayer:FireClient(player)
			end
		end
	end
end)

Well that makes perfect sense because your only showing one server script, so that leads me to believe you only have one server script

How does having a single server script contribute to this problem?

Well so basically if you have two scripts using the same server script its like, for lack of a better analogy like two dogs sharing one bone, its not gonna go well, so what you want to do is either set up parameters for different types of guns like semi, automatic, etc. in the remote params like so

local remoteEvent = game.ReplicatedStorage.remoteEvent

remoteEvent:FireServer("Semi")

------ SERVER SCRIPT
local remoteEvent = game.ReplicatedStorage.remoteEvent

remoteEvent.OnServerEvent:Connect(function(plr,gun_type)
      if gun_type === "Semi"
          --- Do stuff for semi
      end
end)

I’ve made different RemoteEvents for the 2 different guns and I have the same issue. The only thing the Server Script is responsible for is creating the ray, nothing else. So I wouldn’t see this being the issue.

Then explain why its not working then :sweat_smile:

That’s what I’m trying to figure out, why it’s not working.

How about you try to the different server scripts and see what happens (:

Yeah, I get the exact same Issue.

Hm, are you sure about that show me proof?

Dude, I’m not here to argue. Your suggestion didn’t work.

Okay. A suggestion is, Make it so the player can only use one tool at a time.