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

Add GUI Back After Death?

Asked by 10 years ago

So I had a problem of a GUI not staying after the player died. The GUI was one for a specific player and was added as the player connected. So I tried using this script to add the GUI back after the player died.

while true do
    wait(.5)
    game.Players.PlayerAdded:connect(function(player)
        player.CharacterAdded:connect(function(character)
            local humanoid=character:WaitForChild("Humanoid")
            local hum=character.Humanoid.Health
            if hum==0 then
                if player.Name=="Player1" then
                    print("Success!")
                end
            end
        end)
    end)
end

I just made it print Success so I could see if it executed the code properly, but nothing happens in the output.

3 answers

Log in to vote
0
Answered by 10 years ago

You need this event:- http://wiki.roblox.com/index.php?title=API:Class/Player/CharacterAdded

Then clone the gui into the players gui. if you need some code comment as I have a working script

Ad
Log in to vote
0
Answered by
Marolex 45
10 years ago

You do not need a while loop for a function event.

game.Players.PlayerAdded:connect(function(player)
    if player.Name == "Player1" then
        player.CharacterAdded:connect(function(character)
            local humanoid=character:WaitForChild("Humanoid")
            print("Success!")
        end)
    end
end)
Log in to vote
0
Answered by
TopDev 0
10 years ago

You have a few problems here.

One being that this script won't work in Solo mode since the player is created before any scripts, thus being that PlayerAdded has no effect.

Second being, whats happening is the character added event is firing once, when the character resets(after the character is fully reset, and the health = 100 again.) and it's not actually looped, meaning while true do has no effect on it. So basicaly, if the function was firing only when a char is added, and is not looped, it won't detect a health change.

This will work, try it out in Play mode, not solo.

while wait(.5) do
    game.Players.PlayerAdded:connect(function(player)
        player.CharacterAdded:connect(function(char)
            local humanoid = char:WaitForChild("Humanoid")
            local hum = char.Humanoid.Health
            char.Humanoid.Health = 0
            wait(.1)
            if hum == 0 then
                if player.Name=="Captainrex500" then
                    print("Success!")
                end
            end
        end)
    end)
end

It will automaticaly kill you, but if you press F9, you will see it has worked, and printed Success.

Answer this question