Frame fades in, but does not fade out

Hello everyone, I want to make a script that makes a frame fade in when a proximity prompt is activated, and makes the same frame fade out when they press space.

It fades in just fine, but for some reason it doesn’t fade out; rather goes straight to transparent. Here is my code:

LocalScript in the frame:

local screen = script.Parent
local UIS = game:GetService("UserInputService")

local function FadeIn()
	for i = 1, 0, -0.05 do
		wait(0.02)
		screen.Transparency = i
	end
	screen.Transparency = 0
end

local function FadeOut()
	for i = 1, 0, 0.05 do
		wait(0.2)
		screen.Transparency = i
	end
	screen.Transparency = 1
end

game.ReplicatedStorage.MonitorEvent.OnClientEvent:Connect(function()
	wait(2.75)
	FadeIn()
end)

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.Space then
			FadeOut()
		end
	end
end)

LocalScript that detects the button press:

local UIS = game:GetService("UserInputService")

	UIS.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.Space then
				camera.CameraType = Enum.CameraType.Custom
			end
		end
	end)
end)

I appreciate any help.

It looks like you messed up the initial and final transparency.

local function FadeOut()
	for i = 1, 0, 0.05 do

This would make it work:

local function FadeOut()
	for i = 0, 1, 0.05 do
2 Likes

Thanks for the help, I apologise for my stupidity lol

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.