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!
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!