I try lowering transparency but it goes over the limit?

Debby = false
game.ReplicatedStorage.PlayerEventsAndFunctions.Death.OnClientEvent:Connect(function()
	if Debby == false then 
		Debby = true
		print("Stoopid")
	script.Parent.Parent.BlackScreen.Visible = true
	script.Parent.Parent.BlackScreen.BackgroundTransparency = 1
	for i = 1, 50 do
		print("Decreasing")
		script.Parent.Parent.BlackScreen.BackgroundTransparency = script.Parent.Parent.BlackScreen.BackgroundTransparency - 0.02
		print(script.Parent.Parent.BlackScreen.BackgroundTransparency)
		wait()
		end
	end
end)

Output
Stoopid

Decreasing

0.98000001907349

Decreasing

3.0999979972839

Decreasing

5.2199959754944

Decreasing

7.3199939727783

Why is the Background Transparency above 1 even?
And also what have i done wrong to even do this.

The function triggers from touching a block and on death from touching the block the screen fades out (Sorry im not using tween i will add it at the end of the game) but when it fades out the Transprency goes up to like 50? i dont think there is any other code that is touching the transparency of this frame please help

1 Like

Why not just do this instead?

for i= 1,0.1,-0.1 do
    script.Parent.Parent.BlackScreen.BackgroundTransparency = i
    game:GetService("RunService").Heartbeat:Wait() -- avoid using wait like that
end
script.Parent.Parent.BlackScreen.BackgroundTransparency = 0

Also use proper indentation when posting your code please.

Better yet, he should use tween service.

local TweenService = game:GetService("TweenService")
TweenService:Create(script.Parent.BlackScreen, TweenInfo.new(1), {BackgroundTransparency = 0}):Play()
3 Likes

Sorry i forgot about this post, it turns out i had like another part of the code that was adding double the transparency each time. really stupid. but im going to use the tween service code anyway lol