Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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
	......

2 comments

1

Wouldn't the Died event be best since that way you're not checking over and over, 30 times a seconds?

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

This discussion is preserved as it was. New answers, comments, and votes are closed.