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
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)
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.
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
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).