Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When all lives are lost, is it possible to respawn with a certain ammount of lives?

Asked by 10 years ago

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)

1 answer

Log in to vote
0
Answered by 10 years ago

All you have to do is set the Lives back to 9.

--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)
    lives = life --This is all I changed
    player:Remove()  --This will kick the player...you way want to change it
    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)

Ad

Answer this question