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

Why won't the frame fade in?

I want a death message to fade in once you die. But I cannot get it to fade it just instantly appears. How do I fix this?

I'm sorry if my code isn't efficient as I'm new to this.

humanoid.HealthChanged:connect(function()
	local hpMath = humanoid.Health / humanoid.MaxHealth
	hpBar.Size = UDim2.new(hpMath,0,0.25,0)
	if humanoid.Health == 0 then
		print("Dead!")
		local frame = gui.Parent.DeadMessage.Frame
		local text = frame.Message
		for trans = 1,0,-1 do --Won't fade?
			frame.Transparency = trans
			wait(1)
			if frame.Transparency == 0 then
				text.Visible = true
			end
		end
		for timer=2,0,-1 do
			text.Text = "You have died... "..timer
			wait(1)
		end
	end
end)

Thanks.

1 answer

So Transparency is defined as a double ranging [0,1].

In your function, your for loop starts at 1, ends at 0, and decrements by 1; this means, your transparency drops from 1 to 0 instantly, it does not reach all of the decimals in between.

Another addition, Frames do not have a Transparency property, they have a BackgroundTransparency property.

So, to put this all together, replace your current for loop that handles transparency with this:

for trans = 100, 0, -1 do
	frame.BackgroundTransparency = trans/100 -- This will get those in between decimals
	wait(0.01) -- This will cause the entire for loop to take a second to execute.
end
text.Visible = true -- This can be outside the for loop since the code runs in descending order, this will not be run until trans == 0 and the for loop exits

If anymore clarification needs to be added, let me know.

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