First off, the efficiency is an eyesore but i dont know how i could make it better (if i can), and an error keeps saying
22:05:22.324 - Players.Player1.PlayerGui.DeathScreen.Play:1: attempt to index field 'Character' (a nil value)
and for the person who died
22:05:49.675 - death is not a valid member of ScreenGui
and heres my setup http://gyazo.com/10e18bf65f79273159a17fa049208ee2
if game.Players.LocalPlayer.Character.Humanoid.Health == 0 then local main = script.Parent local skull = main.Skull local text = main.death wait(.5) --skull skull.Visible = true skull.ImageTransparency = 1 wait(.01) skull.ImageTransparency = .9 wait(.01) skull.ImageTransparency = .8 wait(.01) skull.ImageTransparency = .7 wait(.01) skull.ImageTransparency = .6 wait(.01) skull.ImageTransparency = .5 wait(.01) skull.ImageTransparency = .4 wait(.01) skull.ImageTransparency = .3 wait(.01) skull.ImageTransparency = .2 wait(.01) skull.ImageTransparency = .1 wait(.01) skull.ImageTransparency = 0 wait(1) --text text.ImageTransparency = 1 wait(.01) text.ImageTransparency = .9 wait(.01) text.ImageTransparency = .8 wait(.01) text.ImageTransparency = .7 wait(.01) text.ImageTransparency = .6 wait(.01) text.ImageTransparency = .5 wait(.01) text.ImageTransparency = .4 wait(.01) text.ImageTransparency = .3 wait(.01) text.ImageTransparency = .2 wait(.01) text.ImageTransparency = .1 wait(.01) text.ImageTransparency = 0 wait(1) wait() end
(yes im aware i need to change the kind of transparency for the text but not even the skull shows)
The problems here are that you're not giving the game enough time for the Character and 'death' to load in, and that you need to set up a function to find when the player dies.
To do this, we'll implement these into the script:
repeat wait() until game.Players.LocalPlayer.Character
main:WaitForChild("death")
These will simply wait until the Character and 'death' are loaded into the game for the script to fire.
To set up the function, we'll take out the if statement, and replace it with an event:
game.Players.LocalPlayer.Character.Humanoid.Died:connect(function()
This fires whenever the Humanoid dies (Health hits 0)
We can also simplify your script a little bit to make it more efficient. To do this, we'll use a for loop. For loops iterate over a code a specified number of times, to make stuff like this more efficient for us.
We'll use it like this:
for i=1,0,-.1 do wait(.01) skull.ImageTransparency = i end wait(1) for i=0,1,.1 do wait(.01) skull.ImageTransparency = i end wait(1)
So now, that entire long script you wrote has been shortened down into much less lines.
Anyways, the final product should be something like this:
repeat wait() until game.Players.LocalPlayer.Character game.Players.LocalPlayer.Character.Humanoid.Died:connect(function() local main = script.Parent local skull = main:WaitForChild("Skull") local text = main:WaitForChild("death") wait(.5) skull.Visible = true for i=1,0,-.1 do wait(.01) skull.ImageTransparency = i end wait(1) for i=0,1,.1 do wait(.01) skull.ImageTransparency = i end wait(1) end)
I think that this should work now, however it problems persist, let me know as soon as you can, and I'll see what I can do.
Well, I definitely hope I helped you out a bit! Also, if you have any further problems or questions, please leave a comment below :P