How to do an combat log system?

i have readed but we have timer now but what about make player can’t leave or else something will do?

That is where the conditional comes in. In your original code, you would check the value of the BoolValue, to see whether it’s true, before executing whatever code prevents the player from leaving combat.

However, when you record the time, instead, in a NumberValue, you would compare it to the current time (tick()) and then find the difference to see how much time passed.

so i will add the script that stop this when player die too

Asinphi thanks for clarifying I think you got this one

2 Likes

To take the player out of “combat mode” manually, you can just set the NumberValue to 0. This will make it look as if a long, long time has passed since the last damage occurrence and any conditionals checking it will believe that the player is out of combat.

set it to 0?? i think we will just set it more than 5

I don’t mean set the time the “in-combat” status lasts :stuck_out_tongue:

I mean setting the value of the NumberValue to 0, as opposed to tick(). This will effectively bring the player “out of combat” immediately.

but in this line if it isn’t greater than 5

it will just mean timer didn’t reach 5 secs yet

so the game will just think player is in combat…

On another note about security, I would advise you that this should all take place on the server. The tag should be created on the server so it’s not exploitable and damage should be handled on the server, meaning that you could check and set the combat status there. Allowing the client to send a RemoteEvent to tell the server that damage occurred is a flaw in your system if exploiters disable that RemoteEvent from firing. If you don’t handle damage server-side already, it’s very good practice to begin doing that.

That checks if less than 5 seconds have passed since the time of the last damage (the value of the NumberValue) and now (tick()).

So if you tell the system that the time of the last damage is 0 (January 1 1970), then it will think that more than 5 seconds have passed and the player is out of combat.

uh how to protect it? …

i think Roblox already protect for us

oh ok thank you
sorry if im hard to understand

1 Like

In some cases, yes, but developers still need to take steps to protect themselves. As I said, it’s best if you handle damage and the combat status entirely server-side.

As for what protection Roblox offers us? They have something called FilteringEnabled which means things created client-side are only there locally and none of it replicates to the server, preventing exploiters from spawning in items. This does not protect from insecure scripts that handle important logic client-side, however.

then how i make protection?

i already think earlier did my game can protect exploiter?

Basically, take the damage on the server and don’t allow the client to dictate when damage occurs.

A demonstration for the new logic I explained to reset the time:

Your first snippet

game.Players.PlayerAdded:Connect(function(plr)
    local lastDamage = Instance.new("NumberValue")
    lastDamage.Parent = game.ReplicatedStorage.CombatLog
    lastDamage.Name = plr.Name

    local function leaveCombat()
        local combat = plr.PlayerGui:FindFirstChild("Combat")
        if combat then
            combat:Destroy()
        end
    end

    local function enterCombat()
        local combat = plr.PlayerGui:FindFirstChild("Combat")
        if not combat then -- In case it's already there
            script.Parent.Combat:Clone().Parent = plr.PlayerGui
        end
    end

    lastDamage.Changed:Connect(function(newValue)
        if newValue == 0 then leaveCombat() return end -- Just in case it was set to 0
        enterCombat() -- Player enters combat
        wait(5) -- It's going to be at least 5 seconds before anything changes
        if tick() - lastDamage.Value > 5 then -- Just in case it was changed and updated since then
            leaveCombat()
        end
    end
end)

Your second snippet

-- Your other tag stuff, first
game.ReplicatedStorage.CombatLog[plr.Name].Value = tick()
2 Likes

i use remoteevent to fire and server will know then it will deal damage. and create tag
i didn’t create tag or deal damage on client

if i don’t use remote event i don’t know what to do now

yes I didn’t allow to allow the client to custom damage

when remote event fired, a script that handles it just want character then deal damage

Thank for your answer.