local player = game.Players.LocalPlayer
script.Parent.MouseButton1Down:Connect(function()
for i = 1,0,0.1 do
player:WaitForChild("PlayerGui"):WaitForChild("blackscreen").Frame.BackgroundTransparency -= i
task.wait(0.02)
end
end)
Hello , My script doesn’t really work well and I don’t know the issue of it not working. Does somebody knows the bug ?
Since you want that to decrease , you need to change 0.1 to -0.1
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Down:Connect(function()
for i = 1,0,-0.1 do
script.Parent.Parent.Frame.BackgroundTransparency = 1- i
task.wait(0.02)
end
end)
You can do this without subtracting from the background transparency and just set it to i directly
And because its subtracting the transparency from an ever changing number, the transparency won’t exactly be 1. It would more so be something like this Iteration 1:
BackgroundTransparency = 0.9
i = 0.1
Iteration 2:
BackgroundTransparency = 0.7
i = 0.2
Iteration 3:
BackgroundTransparency = 0.4
i = 0.3
Iteration 4:
BackgroundTransparency = 0.1
i = 0.4
etc
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Down:Connect(function()
for i = 0,1,0.1 do -- counts down instead of up because it starts at 0 and counts to 1 with increments of 0.1
player:WaitForChild("PlayerGui"):WaitForChild("blackscreen").Frame.BackgroundTransparency = i
task.wait(0.02)
end
end)
Alternatively you could instead use TweenService for a smoother effect (and one that won’t stop the script because of a loop).
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Down:Connect(function()
local goal = {}
goal.BackgroundTransparency = 1
local duration = 1
local easing_style = Enum.EasingStyle.Linear
local easying_direction = Enum.EasingDirection.In
game.TweenService:Create(player:WaitForChild("PlayerGui"):WaitForChild("blackscreen").Frame,TweenInfo.new(duration,easing_style,easying_direction),goal):Play()
end)