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?