I rephrased my question.
--This is a working script.
fade = script.Parent
fadeGoal = 0
fadeRate = 0.05
function updateFade()
local current = fade.BackgroundTransparency
if current < fadeGoal then
fade.BackgroundTransparency = math.min(fadeGoal,current+fadeRate)
elseif current > fadeGoal then
fade.BackgroundTransparency = math.max(fadeGoal,current-fadeRate)
else
fade.BackgroundTransparency = fadeGoal
end
end
Now here's my own script by which doesn't work and need help with,
lif 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 ChangeRate = 0.01
local ChangeGoal = 0
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)
wait(1)
f.BackgroundTransparency = math.max(0,f.BackgroundTransparency-0.01)
end
------------------------------------------
wait(10)
f:Destroy()
end
end
end
script.Parent.Touched:connect(onTouch)
