I have a gui that fades in upon death. It use to be in a "while true do" but I watned to remove it since if I wait too long, it'll start looping. How would I fix this?
local spp = script.Parent.Parent.Parent.Parent.Character.Humanoid local sp = script.Parent if spp.Health == 0 then wait(2.5) sp.BackgroundTransparency= 0.8 wait(.1) sp.BackgroundTransparency= 0.7 wait(.1) sp.BackgroundTransparency= 0.6 wait(.1) sp.BackgroundTransparency= 0.5 wait(.1) sp.BackgroundTransparency= 0.4 wait(.1) sp.BackgroundTransparency= 0.3 wait(.1) sp.BackgroundTransparency= 0.2 wait(.1) sp.BackgroundTransparency= 0.1 wait(.1) sp.BackgroundTransparency= 0 end --while true do is removed, no longer works
It you don't continually check, it will only check once. Since the player won't be dead at that one point, it will just say, okay, I'm done, nothing to do.
We instead just wait for that scenario:
repeat wait() until spp.Health == 0 wait(2.5) for transparency = 1, 0, -0.1 do wait( . 1) sp.BackgroundTransparency = transparency -- use a for loop instead of typing it out over and over! end
Or, we could could just the the Died
event, either
spp.Died:connect(function() wait(2.5) for transparency = 1, 0, -0.1, do .......
or
spp.Died:wait() wait(2.5) for transparency = 1, 0, -0.1 do ......