hi, im trying to make a lives system in my game but i dont know how to do it. the starting text is 'Lives: 4' and then when the player dies it will change to 'Lives: 3' then 'Lives: 2' and so on. but then after 'Lives: 1' it changes back to 'Lives: 4' and resets their curreny (stage) and teleports them to the start co ordinate (-27, 5.7, 53)
here is the script i tried:
if StarterGui.Lives.TextBox.Text = "Lives: 4" and ("Humanoid").Health = 0 then do StarterGui.Lives.TextBox.Text = "Lives: 3" if StarterGui.Lives.TextBox.Text = "Lives: 3" and ("Humanoid").Health = 0 then do StarterGui.Lives.TextBox.Text = "Lives: 2" if StarterGui.Lives.TextBox.Text = "Lives: 2" and ("Humanoid").Health = 0 then do StarterGui.Lives.TextBox.Text = "Lives: 1" if StarterGui.Lives.TextBox.Text = "Lives: 1" and ("Humanoid").Health = 0 then do StarterGui.Lives.TextBox.Text = "Game Over..." wait (3) then Humanoid.Torso.Position = (-27, 5.7, 53) StarterGui.Lives.TextBox.Text = "Lives: 4" end)
this is a normal script (not local) in the Lives GUI in StarterGui
thanks in advance, from poopypigeon245
Create data for your exact idea. Remember programming is made from abstract ideas so you need to create it to make the most sense to the computer.
You will need to keep track of the players lives with a number so use a integer
local lives = 4
You will need to need to check everytime the player dies.
game:GetService('Players').PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() print(player.Name .. " has died!") end) end) end)
You will need to update the text and decrease the player's lives everytime the player dies. So it should look like this
local lives = 4 game:GetService('Players').PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() print(player.Name .. " has died!") lives = lives - 1 -- check how many lifes and update GUI text based on that -- check to see if player has 1 life and died then reset lives back to 4 and reset GUi text -- teleport player to new coordinates here too when lives hit 0 end) end) end)
I would help more but I'm at work. I'll check this post later. Hope I helped a little.