Make Transparent ovwer time not working

Hi!

my third #help-and-feedback:scripting-support topic on my loading screen lol

For some reason, this should make the image transparent, but it’s not.

It’s making this the output:

No console errors

What’s wrong?


the code that’s important in this:

function fade()
	script.Parent.Frame.logo.ImageTransparency -= 0.01
end

script.Parent.Frame.logo:TweenSize(UDim2.new(2, 0, 3, 0), "Out", "Linear", .3, true) -- {0.533, 0},{0.751, 0}
script.Parent.Frame.logo:TweenPosition(UDim2.new(-0.5, 0, -0.619, 0), "Out", "Linear", .3, true) -- {-0.5, 0},{-0.619, 0}
for i = 1,100 do
	wait (0.001)
    fade()
	end
wait(3)

entire loading script’s code:


script.Parent.Parent.Enabled = true
local plrname = game.Players.LocalPlayer.Name
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All,false)
local Assets = {
	game:GetService("Workspace"),
	game:GetService("Players"),
	game:GetService("NetworkClient"),
	game:GetService("ReplicatedFirst"),
	game:GetService("ReplicatedStorage"),
	game:GetService("ServerStorage"),
	game:GetService("StarterPack"),
	game:GetService("StarterPlayer"),
	game:GetService("Teams"),
	game:GetService("SoundService"),
	game:GetService("Chat"),
	game:GetService("LocalizationService"),
	game:GetService("Lighting")
} 
local text = script.Parent.Frame.Frame.TextLabel
local barImg = script.Parent.Frame.Frame.ImageLabel
local ContentProvider = game:GetService("ContentProvider")
function fade()
	script.Parent.Frame.logo.ImageTransparency -= 0.01
end
pcall(function()
	for i = 1, #Assets do
		local Asset = Assets[i]

		text.Text = "Configuring "..Asset.Name.." [".. i .. " / "..#Assets.."]"
		ContentProvider:PreloadAsync({Asset})
		local Progress = i / #Assets
		barImg:TweenSize(UDim2.new(Progress, 0, 1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 1, false)
		wait(0.3)
	end
end)

wait(0.1)
for i = 1,5 do 
	barImg:TweenSize(UDim2.new(1, 0, 1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 1, false)
end
wait(1)
local Info = TweenInfo.new(1)
local Frames = {script.Parent.Frame,script.Parent.Parent.Frame.Frame}
for i, frame in pairs(Frames) do
	local Tween = game:GetService("TweenService"):Create(frame,Info,{BackgroundTransparency=1})
	Tween:Play()
end
local Tween_2 = game:GetService("TweenService"):Create(script.Parent.Parent.Frame.Frame.Frame.TextLabel,Info,{TextTransparency=1})
local Tween_3 = game:GetService("TweenService"):Create(script.Parent.Frame.Frame.ImageLabel,Info,{ImageTransparency=1})
local Tween_4 = game:GetService("TweenService"):Create(script.Parent.Frame,Info,{BackgroundTransparency=1})
Tween_2:Play()
Tween_3:Play()
Tween_4:Play()
wait(3)
script.Parent.Frame.logo:TweenSize(UDim2.new(2, 0, 3, 0), "Out", "Linear", .3, true) -- {0.533, 0},{0.751, 0}
script.Parent.Frame.logo:TweenPosition(UDim2.new(-0.5, 0, -0.619, 0), "Out", "Linear", .3, true) -- {-0.5, 0},{-0.619, 0}
for i = 1,100 do
	wait (0.001)
    fade()
	end
wait(3)

for i = 1,15 do
	wait (0.01)
	script.Parent:TweenPosition(UDim2.new(1, 0, 0, 0), "Out", "Linear", 1, true)-- {0.25, 0},{0.16, 0}1
end
wait(3)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All,true)
local BM = script.Parent.Parent.Parent.WelcomeScreen.Beta
wait (2)
if BM.Visible == false then
	local LocalScript = game.Workspace.PlayerEntered:WaitForChild("CutsceneScript",10):Clone()
	LocalScript.Parent = game.Players.LocalPlayer.Character
	LocalScript.Disabled = false
	BM.Visible = true
else 
	
end


Thanks for any help!

Try… I’m not sure Roblox supports -=

function fade()
	script.Parent.Frame.logo.ImageTransparency = script.Parent.Frame.logo.ImageTransparency-0.01
end

They do, I know for a fact.
(3) += testing - Roblox

I forget how to un/copylock, but here’s the code:

One of them is -=, and one of them is a = a + 1

1 Like

Then have you printed anything in the fade function to see if anything is actually happening. By the way, you should probably use TweenService instead of using a for loop. See this TweenService | Roblox Creator Documentation

It’ll handle the fading/movement for you.

Example:

local TweenService = game:GetService("TweenService")
 
local goal = {}
goal.ImageTransparency = finalResultHERE -- CHANGE ME
 
local tweenInfo = TweenInfo.new(2.5) -- time you want it to talk
 
local tween = TweenService:Create(GUIHERE, tweenInfo, goal)
 
tween:Play()

People when I use while true do: NEVER NO NO NO
People when I use while wait() do: NO WAY
People when I use for i loops: No way!

It’s getting better!

TweenService is for moving and scaling, I dont feel like changing how I script completely for the third time.

It’s not just for moving and scaling, it can be used to change the transparency in this case.


I’m getting the message

Like I said before you can just remove this, and change it to match this code:

local TweenService = game:GetService("TweenService")
 
local goal = {}
goal.ImageTransparency = finalResultHERE -- CHANGE ME
 
local tweenInfo = TweenInfo.new(2.5) -- time you want it to talk
 
local tween = TweenService:Create(GUIHERE, tweenInfo, goal)
 
tween:Play()

It’s way more efficient than what you’re doing. You’re already doing something like this at the end of your code, like your one liner…

game:GetService("TweenService"):Create(GUIHERE,TweenInfo.new(TIMEHERE),{ImageTransparency=FINALRESULTHERE}):Play()

local tween = TweenService:Create(GUIHERE, tweenInfo, goal)

image
How would I make it do this? Just logo?

If that’s what you want to fade, correct.

local TweenService = game:GetService("TweenService")
 
local goal = {}
goal.ImageTransparency = 1-- CHANGE ME
 
local tweenInfo = TweenInfo.new(2.5) -- time you want it to talk
 
local tween = TweenService:Create(script.Parent.Frame.logo, tweenInfo, goal)
 
tween:Play()

Why don’t you change that to:

local RS = game:GetService("RunService")
for i = 0,1,.01 do -- Edit: accidentally flipped the limits
    RS.RenderStepped:Wait() --regular waits are inconsistent, and cannot wait a shorter interval than .03 anyway
    script.Parent.Frame.logo.ImageTransparency = i --no need to create a separate function if it's only going to be one line
end

That way you can still get a consistent fade without having to use the tween service.

Just placing my reasoning for this in an edit instead of a new comment:
The OP seems to be making a loading screen to block the player’s view before anything is loaded. The thread being blocked would be a good thing in this case because you wouldn’t want this local script to do anything like show menus while the title screen is being faded. But if you don’t want the thread to be blocked, that’s what coroutines are for, and if you wrapped the fade with a coroutine, it would not block the thread while also doing the exact same thing as a tween, with less setup and no need to connect an event to detect it finishing.

I just have a personal gripe with how the TweenService requires so much setup just for something minor, and you have to create a whole new set of goals and a new info object just to change one thing. So my solution is simply showing an easier way of doing something when you don’t need to be perfect.

1 Like

I do agree you could do this, but this isn’t what for loops are for, and it’s arguably much more efficient to use TweenService.

What do you mean this isn’t what for loops are for? They are a way to loop things within a set range, this is exactly what they are for. This would do the same thing as the tween service in this context, but it does it in less code.

But TweenService is designed, and built for this exact case. That for loop is thread blocking, and is taking up more time than the TweenService would otherwise as it’s using a wait. And not to mention, TweenService provides much more customization options out of the box.

If you’d like to discuss this more, I’d recommend we take it to messages, as we’re just continuing to bump this thread.