How do i make a Combat logging and lives system? [URGENT]

so I’ve read a lot about combat logging on the dev forum and it hasn’t worked at all so i decided to come here and ask for help. 1st off how would i go about making a combat logging system that takes away 1 life when you leave while in combat? 2nd how would i make the lives system and so a players progression (tools stats values etc.) gets wiped? I’m pretty sure i would use an IntValue to store the lives but I feel like exploiters could figure out how to bypass that, should i use remote events to detect if a life has been lost? Anyway to sum it up, I really need help with a combat log system long with a life system that wipes a players stats clean when they lose all 3 lives.

3 Likes

Can you elaborate more on what the ‘Lives’ system is?

  • What does it do?
  • What happens when your lives run out?
  • etc
1 Like

so i want a player to have 3 lives, when the player has 1 life left i want them to get teleported to a different place in the map to recover a life but if they die there they lose their last life and all their progress gets deleted (tools, money, values etc.) and i would also like a gui that displays the players lives but i already know how to do that

How do you recover lives in the area you get teleported to?

1 Like

there will be mobs surrounding a tower, if you get to the top of the tower you get teleported to your original position where you were before you died

For the Lives, simply create a Leaderstat value with a Script which datasaves with DataStoreService.

*Make an attempt of loading the Lives value when the player joins, but if the data doesn’t exist then simply set it to 3.
Save how many Lives the Player has when they leave but if their Lives are 0 then reset it back to 3 and reset all other data (for tools, etc)

*There are many good tutorials on YouTube for datasaving.

When you detect if a player joins, also make a variable for their character (to detect dying).

Do it along the lines of

Player.CharacterAdded:Connect(function(Char)
local Hum = Char:FindFirstChild(“Humanoid”)

Hum.Died:Connect(function()
Lives.Value -= 1 — Subtract a Life when the player dies
if Lives.Value == 0 then Player:Kick(“You ran out of lives!”) end
end)
end)
1 Like

so i have tried using datastores but i really suck at it lol, do you mind helping me with that?

Here is a good Tutorial on DataStoreService that helped me first understand it:

2 Likes

alr im watching rn, thank you ᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼

2 Likes

so right now i have this code

local DataStoreService = game:GetService("DataStoreService")

local playerData = DataStoreService:GetDataStore("playerData")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local LivesLeft = Instance.new("IntValue")
	LivesLeft.Name = "LivesLeft"
	
	LivesLeft.Parent = leaderstats
	
	local data 
	local success, errormessage = pcall(function()
		data = playerData:GetAsync(player.UserId.."-LivesLeft") 
	end)
	
	if success then 
		LivesLeft.Value = data
	else
		print("Error while getting your data")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local success, errormessage = pcall(function()
		playerData:SetAsync(player.UserId.."-LivesLeft", player.leaderstats.LivesLeft.Value)
	end)
	
	if success then
		print("Data successfully saved!")
	else
		print("There was an error while saving the data")
		warn(errormessage)
	end
	
end)

so how would i make it so new players get 3 lives?

1 Like
local DataStoreService = game:GetService("DataStoreService")

local playerData = DataStoreService:GetDataStore("playerData")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local LivesLeft = Instance.new("IntValue")
	LivesLeft.Name = "LivesLeft"
	
	LivesLeft.Parent = leaderstats
	
	local data 
	local success, errormessage = pcall(function()
		data = playerData:GetAsync(player.UserId.."-LivesLeft") 
	end)
	
	if success then 
		LivesLeft.Value = data
	else
		LivesLeft.Value = 3 — Set value to 3 for new players
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local success, errormessage = pcall(function()
		playerData:SetAsync(player.UserId.."-LivesLeft", player.leaderstats.LivesLeft.Value)
	end)
	
	if success then
		print("Data successfully saved!")
	else
		print("There was an error while saving the data")
		warn(errormessage)
	end
	
end)
2 Likes

ok so the data store works (sorry for responding so late i went to sleep) but how would i make it so it wipes all the player data? sets all the values to the default values and removes all the tools?