Combat Tag not working properly

This script is located in a ScreenGui

local RS = game:GetService("ReplicatedStorage")
local RUS = game:GetService("RunService")

local Player = script:FindFirstAncestorWhichIsA("Player")
local Character = Player.Character or Player.CharacterAdded:Wait()

local CombatTimer

RS.WeaponRemotes.CombatTag.Event:Connect(function(plr)
	if plr == Player.Name then
		CombatTimer = tick()
		Character.InCombat.Value = true
	end
end)

RUS.Heartbeat:Connect(function()
	if Character.InCombat.Value == true then
		print("in combat | time elapsed: "..tick() - CombatTimer)
		if tick() - CombatTimer >= 15 then
			Character.InCombat.Value = false
			CombatTimer = nil
		end
	end
end)

When first firing the remote, the counter starts and goes on for 5 seconds, but then it stops, and when firing the remote again the counter immediately ends. I don’t know what’s wrong with it?

Try rewriting these parts of your code as such

….Event:Connect(function(plr)
   if plr.Name == Player.Name and not CombatTimer do
      — Do relevant stuff
   end
end)
Character.InCombat.Changed:Connect(function(val)
   if not val then return end
   task.spawn(function()
      repeat 
         ("in combat | time elapsed: "..tick() - CombatTimer)
         task.wait()
      until
         tick() - CombatTimer >= 15
   end)
end)