Is there a "Best Method" to change the property of an object or GUI, like for example the transparency of a Frame in a GUI. There are two ways that I know of, I could either use a for-loop or TweenService to change the transparency. Is there another way that I am missing?
Does one cause more lag? Can one be more efficient? Does one look more appealing?
Here's a for-loop for the transparency of a block
local block = script.Parent while true do for i = 1, 10 do block.Transparency = block.Transparency + 0.1 wait(1) end wait(2) for i = 1, 10 do block.Transparency = block.Transparency - 0.1 wait(1) end wait(2) end
Here's the TweenService for the transparency of a block
local block = script.Parent local ts = game:GetService("TweenService") local tween = nil function tweenObject(t) local info = TweenInfo.new(10) return ts:Create(block, info, {Transparency = t}) end while true do tween = tweenObject(1) tween:Play() wait(12) tween = tweenObject(0) tween:Play() wait(12) end
Which one is the better method to use? Or under some circumstances, which one should be used?
Tweens are basically just for loops. So yeah, both can be used, they have no significant differences in performance. The only thing different is that Tweens do not yield the thread, while for loops yields the thread until it's done. Tweens also have some additional features (easing styles, easing directions, repeat count, etc.). It's up to you to decide which to use in different use cases.