Soo I am trying to make like when you touch a brick a gui just tween’s it’s transparency but I really don’t know how to do that, and I tried searching it and some code that gets that task done but it looks very bad, code:
for i = 0, 1, 0.1 do
wait(0.1)
script.Parent.TextLabel.Transparency = i
end
print("Finished")
Always make sure to use cleaner and more efficient code, never do that multiple line. This is exactly what a for loop is for.
Or if you’re looking for tweening then just a for loop do
local TweenService = game:GetService("TweenService")
local time = 1 --this will tell you how much it would take for the tween to finish
local tween = TweenService:Create(script.Parent.TextLabel, TweenInfo.new(time), {Transparency = 1})
tween:Play()
local Info = TweenInfo.new(1)
local Tween = game:GetService("TweenService"):Create(script.Parent,Info,{TextTransparency=1})
Tween:Play()
print("Finished")
Don’t use RenderStepped as a substitute for loop intervals ever. RenderStepped should be scarcely used in your code as it executes before frames and thus has the potential to delay or block rendering if you’re using it inappropriately. RenderStepped realistically should only be used for small immediate updates that should be present before any rendering, such as camera and character updates. Use Heartbeat here instead. If it’s important transparency comes before physics are simulated, use Stepped.
I’ve tried the loop code, it works but only makes the part fade out and never fade back in. How could I make it neverending to have the part have full transparency to opaque then back to full transparency and so on?
You simply make a separate tween, where the transparency is set back to 0, play it as well, do that along with the other code in a while loop. You should do that on your own, but here is a version of what I said.
local TweenService = game:GetService("TweenService")
local time = 1 --this will tell you how much it would take for the tween to finish
local FadeIn = TweenService:Create(script.Parent.TextLabel, TweenInfo.new(time), {Transparency = 1})
local FadeOut = TweenService:Create(script.Parent.TextLabel, TweenInfo.new(time), {Transparency = 0})
while true do
FadeIn:Play()
FadeIn.Completed:Wait() --this will yield/stop the script until FadeIn tweem has finished
FadeOut:Play()
FadeOut.Completed:Wait() -- stops until FadeOut is done, google :Wait for more info
end
For some cases, TweenService is better, as TweenService does not yield the current thread, which is useful if you need to do multiple things at the same time whilst a tween or animation is running. You can also do it in one line
I know, that tween service is much better and easier, i already said it.
And by saying “if you need to do multiple things at the same time whilst a tween or animation is running” you mean, that roblox will wait for function (for i=100, 1, -1 do) before doing next lines? If yes we can just use task.spawn function
task.spawn(function()
for i=100, 1, -1 do
script.Parent.TextLabel.Transparency = i/100
end
--or other, everything we want
end)
it’s will make roblox don’t wait for function’s ending
also sorry for mistakes, i don’t know english very well.