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

How do you make a Gui appear when you die?

Asked by 10 years ago

Hey, guys! I am trying to make a Gui that appears whenever a player dies in the game, to make a "You died!..." Gui. You might've seen an example of this in Apocalypse Rising, etc. Anyways, this is what I've tried so far:

The Structure: ->StarterGui ->ScreenGui -> Frame ->TextLabel ->Script

Inside the Script:

local Player = script.Parent.Parent.Parent.Parent.Parent
local character = Player.Character
health = character:FindFirstChild("Humanoid")

while true do
    if health then
        if health.Health <= 0 then
            script.Parent.Visible = true
        elseif health.Health > 0 then
            script.Parent.Visible = false
        end
    end
end

If anyone can explain to me what I am doing wrong, I'd gladly appreciate it. Thanks!

0
6 Parents not 5 Hybric 271 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

How about instead of using a while true do end loop, why not use the .Died event? Heres what I mean;

repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") --I like to use this to wait for the requirements; this will repeat waiting until the Player spawns, the Player's Character spawns, and the Humanoid spawns within the Player's Character
local Player = game.Players.LocalPlayer --This is the Player
local character = Player.Character --This is the Player's Character
local health = character.Humanoid --This is the Player's Humanoid within Character

health.Died:connect(function() --Here is the `.Died` event; this will fire when the Player has died
script.Parent.Visible = true --It will enable the Visibility for the Gui
end) --This `end)` ends the `.Died` event; ends the code; ends the code block

Hope this helped!

0
You are a boss. Thank you so much!~ dpark19285 375 — 10y
0
No problem, man. :) I was glad to help. :) But I don't really answer allot of questions because they're more advanced than me. Haha! :P TheeDeathCaster 2368 — 10y
Ad

Answer this question