Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Best way to change the property an object or gui?

Asked by 6 years ago

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?

0
There is no major performance difference. As you may know, TweenService allows for Enum choice and various other customization options which would otherwise need to be added in via math when it comes to interpolation - which is why it is more preferable in some cases. SummerEquinox 643 — 6y
0
Note that with a for loop, you can set the step to .1. Thus simplifying your example for loops immensely. Example: for i = 0, 1, .1 do block.Transparency = i. Similarly, you can do a negative step. User#25115 0 — 6y
1
Example: for i = 1, 0, -.1 do block.Transparency = i. User#25115 0 — 6y

1 answer

Log in to vote
0
Answered by
LeadRDRK 437 Moderation Voter
6 years ago
Edited 6 years ago

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.

0
Tweening is actually more efficient in terms of performance since it's a Roblox thing and not actually Lua BlackOrange3343 2676 — 6y
Ad

Answer this question