Hello, this is a simple tutorial on how to make a Life system! It’s recommended that you come here with simple table knowledge and knowledge on the Players Service.
Now a good thing about this is that its Server-Sided, so exploiters can’t do anything to this script, or give themselves infinite amounts of lives.
A simple way to make this can be this script right here!
Skip to 0:57!!!
local Players = game:GetService("Players") -- Getting the player Service, so that we can find out if a new player joins.
local Lives = {} -- A Table, where we store all of the players and how many lives they have.
local Debug = true -- Just Something Extra just incase you want to find out if values are accurate :thumbsUp:.
Players.PlayerAdded:Connect(function(player) -- Checking for when a new player joins.
Lives[player.Name] = 3 -- Setting the players amount of lifes, you can change this.
player.CharacterAdded:Connect(function(character) -- Checking for the new players character, so we can get the humanoid.
local Humanoid = character:FindFirstChildOfClass("Humanoid") -- Humanoid, to check if its health is equal to zero.
Humanoid.Died:Connect(function() -- Fire's when the Humanoid's Health is Zero.
Lives[player.Name] -= 1 -- Taking away a life from the Humanoid.
if Debug then print(player.Name.." Lives: "..Lives[player.Name]) end -- Will print out the amount of lives the player Currently has if debug is on.
if Lives[player.Name] == 0 then -- If the player's lifes are zero then.
if Debug then print(player.Name.." Lives: "..Lives[player.Name]) end -- Printing out the players name and there lives.
Lives[player.Name] = 3 -- Reseting the Players life to x value.
end
end)
end)
end)
This script basically creates a Life Table, to store every player life value’s into, and then we check for when a player joins, so that we can get their character and humanoid to check if they died.
If they did die, then the Humanoid.Died
function will fire, and it will subtract the player who die’s Lives by 1, You can change the amount of life’s taken away if you’d like.
If the player’s life is 0, then it will set there lives to the default amount of lives, you can also change this and or print out the players amount of lives if you have Debug
on true.
If you want to make something a bit more advanced like a tween, you can get the PlayerGui from the Player local PlayerGui = player:FindFirstChild("PlayerGui")
, and then you can get a frame or another GUI element and animate them with tweens, so that you can emulate a death message.
You can always just make the frame visible or up the transparency though, If you don’t know how to tween.
Sorry for the bad video quality and long video, I need a new computer