I'm working with a script that gives a player a specific amount of lives, and when the player looses their lives, they respawn with that specific amount. Is it possible to script a way to respawn with a certain amount of lives?
Here's the Lives script I'm working with:
--Made by Intent
life = 9 --How many lives
function onHumanoidDied(humanoid, player)
local lives = player:findFirstChild("Lives")
lives.Value = lives.Value - 1
if lives.Value <= 0 then
local m = Instance.new("Message")--Hint or message?
m.Text = "GAME OVER"--*Screams* *Throws controller at screen*
m.Parent = player
wait(4)
player:Remove()
end
end
function onPlayerRespawn(property, player)
if property == "Character" and player.Character ~= nil then
local humanoid = player.Character.Humanoid
local p = player
local h = humanoid
humanoid.Died:connect(function() onHumanoidDied(h, p) end )
end
end
function onPlayerEntered(newPlayer)
local lives = Instance.new("IntValue")
lives.Name = "Lives" --Noname...reminds me of 1st grade...:D
lives.Value = life
lives.Parent = newPlayer
while true do
if newPlayer.Character ~= nil then break end
wait(5)
end
local humanoid = newPlayer.Character.Humanoid
humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )
newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
lives.Parent = newPlayer
end
game.Players.ChildAdded:connect(onPlayerEntered)
