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

[RESOLVED]Why isn't this script working when the 'while true do' is removed?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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
    ......
1
Wouldn't the Died event be best since that way you're not checking over and over, 30 times a seconds? Perci1 4988 — 9y
0
Yes, the Died event would be preferable. If this is only being done for a single thing, though, it isn't any work at all to just check Health, so it's not harmlful BlueTaslem 18071 — 9y
Ad

Answer this question