How to do an combat log system?

I have tried to do a combat log system but

** I have a problem with it…**

I have tried to create BoolValue in ReplicatedStorage

game.Players.PlayerAdded:Connect(function(plr)
local combatvalue = Instance.new("BoolValue")
combatvalue.Parent = game.ReplicatedStorage.CombatLog
combatvalue.Name = plr.Name
combatvalue.Changed:Connect(function(value) -- register event when combatvalue value changed

if value == true or value == false then -- make sure value value changed
end
 if value == true then
script.Parent.Combat:Clone().Parent = plr.PlayerGui -- inside gui just have gui that say Your risk is in risk, do not leave the game!
else
if plr.PlayerGui:FindFirstChild("Combat") then 
plr.PlayerGui:FindFirstChild("Combat"):Destroy()
end
end
end
end)

This is script that deal damage in script (ClassName = Script)

I use RemoteEvent to fire and this script will be working

actually i have more but this is just some of it

local b = Instance.new("ObjectValue")
			b.Parent = chr.Humanoid
			b.Name = "Tag"
			b.Value =  plr 
game.ReplicatedStorage.CombatLog[plr.Name].Value = true -- Variable plr = client that fire remote event
wait(5)
game.ReplicatedStorage.CombatLog[plr.Name].Value = false

Now the problem is…

There is a problem in a line that change combat log value because if it runs multiple time, it will just change to false before it reaches 5 seconds

Sorry if it no understandable…

Sorry for bad English and thanks to all answer :slight_smile:

2 Likes

What do you mean by a combat log system, you mean when they are in combat and leave the game?

1 Like

yes, sorry if i can’t make you understand because i’m bad at english

Its fine man,Well first off do you even have a combat system?

like weapon? [this is 30 characters!!]

I have the sword that can deal damage, can tag humanoid…

Well for a combat system what you could do is if the player is hit by something put them in a table called like Attacked, and then tie a player removing event since this is handled on the server and check if the player that was “removed” was also inside of the Attacked table, and if they were do stuff heres a rough example

Attacked = {}

table.insert(Attacked,plr.Name)
game.Players.PlayerRemoving:Connect(function(player)
      if table.find(Attacked,player.Name) then
        print(plr.Name.." has logged out while in combat")
    end
end)

ok i’ll try it tomorrow
but what about like passed 10 seconds then player isn’t on risk anymore

Then youd just remove them after 10 seconds using tick like so

Attacked = {}

table.insert(Attacked,plr.Name)
local time_passed = tick()
spawn(function()
      if tick() - time_passed >= 10 then
        table.remove(Attacked, plr.Name)  
     end
end)

The problem you have here is a logic issue. 5 seconds after each time damage occurs, it will always set the value to false no matter what. This means that, yes, if it happens multiple times within 5 seconds, it will be set to true then false again before the time is over because the last damage occurrence sets it to false.

How to fix this? You’ll need to reset the cooldown when the damage happens again. Instead of storing it as a boolean, you ought to store the time of the last damage with tick(), which is the time in seconds since January 1, 1970. It is an accurate, precise measure of time.

To utilize this, you would change the BoolValue to a NumberValue and store the tick() when damage occurs; this saves the time that the last damage occurred.

game.ReplicatedStorage.CombatLog[plr.Name].Value = tick()

Then, when you reference the CombatLog value, you can check it like this:

if tick() - game.ReplicatedStorage.CombatLog[plr.Name].Value < 5 then -- equivalent to if game.ReplicatedStorage.CombatLog[plr.Name].Value == true in your previous code

uh but what if it run multiple time because my weapon when passed 1 seconds player can just attack again.

Then you gonna have to add a debounce

This would be the case if you don’t reset the cooldown. Here’s a scenario:

Player deals damage - the time starts.

9 seconds later - The player deals damage again.

1 second later - The time ends, it’s set to false.

uh debounce for 10 seconds !???

Adding the debounce and resetting the time are two different things; I’m assuming the OP would rather reset the time but it depends on what he wants.

1 Like

but i want just when pass 1 second player can attack again 10 seconds is too long

But you just said earlier you wanted 10 seconds to pass

i think i select just reset timer because debounce 10 seconds is too long

i think i mean just remove player from risk table and player can leave safety.

I believe the OP meant that the CombatLog wasn’t a debounce for damage, but maybe it was something else such as an “in-combat” status (in which case, resetting the time would probably be the desirable thing to do).

1 Like