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

Why Wont these guis show?

Asked by 8 years ago

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)

0
I don't really know why they're not becoming visible, Check ZIndex? and besides that, try to use for loops : > NotSoNorm 777 — 8y

1 answer

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
8 years ago

Updated


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

0
now i dont get errors, but it doesnt go after i die bubbaman73 143 — 8y
0
Ah, sorry about that. I added in a function that should fire whenever the player dies, so it should all work correctly now. dyler3 1510 — 8y
1
I heard you can't use WaitForChild() on the character because technically character isn't an actual child of player. SpazzMan502 133 — 8y
0
Ah, I believe, you're right. It's stored as a property of the player, thanks for pointing that out. dyler3 1510 — 8y
Ad

Answer this question