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

How do I make a gui fade in when a player dies?

Asked by
quinzt 201 Moderation Voter
5 years ago

Ive been trying to make a death screen for awhile now, and this is the last thing i need to do. I want to make it so that when you die, A gui will fade in that will say "You died" I have the "You died" part done, but I need to know how to make it fade in.

I am really bad at scripting so this is all i could come up with, but ofc it doesnt work

game.Players.LocalPlayer.Character:WaitForChild('Humanoid').Died:connect(function()
    script.Parent.ImageTransparency = 1
    wait(0.1)
    script.Parent.ImageTransparency = 0.9
    wait(0.1)
    script.Parent.ImageTransparency = 0.8
    wait(0.1)
    script.Parent.ImageTransparency = 0.7
    wait(0.1)
    script.Parent.ImageTransparency = 0.6
    wait(0.1)
    script.Parent.ImageTransparency = 0.5
    wait(0.1)
    script.Parent.ImageTransparency = 0.4
    wait(0.1)
    script.Parent.ImageTransparency = 0.3
    wait(0.1)
    script.Parent.ImageTransparency = 0.2
    wait(0.1)
    script.Parent.ImageTransparency = 0.1
    wait(0.1)
    script.Parent.ImageTransparency = 0
    wait(0.1)
end)
0
Instead of that make another script. nazarthatjustwant -5 — 5y
0
Instead of that make another script. At first, with "ImageTransparency", you can make a loop "for i = 1,10 do wait(0.1) script.Parent.ImageTransparency = script.Parent.ImageTransparency - 0.1" And try to not use ":WaitForChildren()". Instead of that make first line : "local Human = game.Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid")", then Human.Died:Connect (and e.t.c.) nazarthatjustwant -5 — 5y

2 answers

Log in to vote
1
Answered by
starmaq 1290 Moderation Voter
5 years ago
Edited 5 years ago

Nice try, you did get almost everything right, but the reason this is not working is maybe because you were refering to game.Players.LocalPlayer in a server script (a normal script) which you can't do. You have to do it in a loca script, that also applies for GUIs, I'm assuming this server script is parented to a UI (script.Parent), which won't work out as well, UIs need to be controlled from a local script, because they are local or in other words client-sided, meaning they are handled from the player's computer (also known as the client) and not the server. So change this to a local script, and another thing to point out is, this part

    script.Parent.ImageTransparency = 1
    wait(0.1)
    script.Parent.ImageTransparency = 0.9
    wait(0.1)
    script.Parent.ImageTransparency = 0.8
    wait(0.1)
    script.Parent.ImageTransparency = 0.7
    wait(0.1)
    script.Parent.ImageTransparency = 0.6
    wait(0.1)
    script.Parent.ImageTransparency = 0.5
    wait(0.1)
    script.Parent.ImageTransparency = 0.4
    wait(0.1)
    script.Parent.ImageTransparency = 0.3
    wait(0.1)
    script.Parent.ImageTransparency = 0.2
    wait(0.1)
    script.Parent.ImageTransparency = 0.1
    wait(0.1)
    script.Parent.ImageTransparency = 0
    wait(0.1)

Logically speaking, it should work as you'd think it would, but there is a much more efficient way to do it that offers more readability, using for loops. For loops are basically loops that loop a certain amount of times.

for i = 0, 10, 1 do
    print(i)
end

This loop will loop from 0 to 10, going up by 1 each loop. i is the value the loop is currently at. So it would print 0 1 2 3 4 5 6 7 8 9 10.

for i = 0, 14, 2 do
    print(i)
end

This would go from 0 to 14 going up by 2, so it would technically loop 7 times.

We can utilise this, we can go from 0 (invisible) to 1 (visible), by 0.1 for example so it does it slowly, and we set the transparency value to i, because represents the value that we are making go from 0 to 1. Think a bit about what we did, it's pretty cool.

game.Players.LocalPlayer.Character:WaitForChild('Humanoid').Died:connect(function()
   for i = 0, 1, 0.1 do
    wait(0.1) --we add a wait so it doesn't finish the loop instanly
    script.Parent.Transparency = i
  end
end)

And just in case you are wondering what :WaitForChild() is, it basically waits for an object to load, in this case if humanoid didn't load yet it would wait for it.

0
Ok so it worked, but its backwards. The transparency starts at 1, and ends at 0 which isnt what i need to happen quinzt 201 — 5y
0
ignore my comment i read everything wrong xd  Godlydeathdragon 227 — 5y
0
If you want the text (or a black screen w/ the text) to fade IN, you want to REDUCE transparency from 1 (100% invisible) to 0 (0% invisible). Anyways, if you really do want it reversed, it's a simple change: for i = 1, 0, 0.1 do Juolite395 11 — 5y
0
^ starmaq 1290 — 5y
0
That's why I said think about it logically! starmaq 1290 — 5y
Ad
Log in to vote
0
Answered by
Nikkulaos 229 Moderation Voter
5 years ago

here try this:

game.Players.LocalPlayer.Character:WaitForChild('Humanoid').HealthChanged:Connect(function(health)
    if health <= 0 then
        script.Parent.Visible = true
        script.Parent.ImageTransparency =  0
        for i  =1,10 do
            script.Parent.ImageTransparency =  script.Parent.ImageTransparency -0.1
            wait(0.1)
        end
    end
end)

tell me if theres any errors still and ill help out

0
there's a function for the humanoid when you die lmao you don't need to check if the health is 0 VitroxVox 884 — 5y
0
Nice answer, but always remember to explain what you did For instance what the `.HealthChanged` event starmaq 1290 — 5y

Answer this question