Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
Edited 7 years ago

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 answer

Log in to vote
1
Answered by 7 years ago
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?

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" shadownetwork 233 — 7y
Ad

Answer this question