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

How do you make the screen fade into white when a specific object is touched?

I want the screen to fade into white basically.

function onTouch(hit)

	if hit.Parent:FindFirstChild("Humanoid") ~= nil then

		if game.Players:FindFirstChild(hit.Parent.Name) ~= nil then
		local player = game.Players:FindFirstChild(hit.Parent.Name)

			if player:FindFirstChild("PlayerGui"):FindFirstChild("ScreenGui") == nil then
			sg = Instance.new("ScreenGui")
			sg.Parent = player:FindFirstChild("PlayerGui")
			
end

    if player.PlayerGui.ScreenGui:FindFirstChild("MessageBox") == nil then

		local f = Instance.new("Frame")
		f.Name = "WhiteFrame"
		f.Position = UDim2.new(0, 0, 0, 0)
		f.Size = UDim2.new(1,0, 1,0)								
		f.Parent = player.PlayerGui:FindFirstChild("ScreenGui")
        f.BackgroundTransparency = 1
        f.BackgroundColor3 = Color3.fromRGB(255,255,255)
        
if f.Name == ("WhiteFrame") and f.BackgroundTransparency ~= 1 then 
for i=1, 10 do 
wait(0.1) 
f.BackgroundTransparency = f.BackgroundTransparency - 0.1 
end 
wait(.5)
for i=1, 10 do
wait(0.1)
f.BackgroundTransparency = f.BackgroundTransparency + 0.1
		end
	end
end

wait(10)
f:Destroy()
		end
        
script.Parent.Touched:connect(onTouch)


1 comment

1 answer

✓ Accepted answer
repeat
	f.Transparency = f.Transparency - 0.1
until f.Transparency == 0
wait(0.5)
repeat
	f.Transparency = f.Transparency + 0.1
until f.Transparency == 1

is that simple enough?

1 comment

0

The only problem I can see is if the starting transparency is 0.95 then it will never hit 0 and would loop forever. You could fix this by changing "until f.Transparency == 0" and "until f.Transparency == 1" to "until f.Transparency <= 0" and "until f.Transparency >= 1"

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