Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you make a Gui appear when you die?

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!

1 comment

0

6 Parents not 5

1 answer

✓ Accepted answer

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!

2 comments

0

You are a boss. Thank you so much!~

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

This discussion is preserved as it was. New answers, comments, and votes are closed.