So I am making a procedurally animated GUI Heart that grows and shrinks throughout the game’s lifetime. I am unsure how to make it grow and shrink infinitely and this is my current code:
function animate_heart()
local info = TweenInfo.new(
0.5,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut,
math.huge,
true
)
local tween = game:GetService('TweenService'):Create(GUI, info, {Size = GUI.Size + UDim2.new(0, offset_X, 0, offset_Y)})
tween:Play()
end
animate_heart()
Considering that math.huge
is only the highest set number in Lua, the Tween will eventually stop. One alternative that I have tried to implement when making my infinite Tween is using RunService.RenderStepped
, but that solution simply just doesn’t even work. This is the other variation of the code which doesn’t work:
function animate_heart()
local info = TweenInfo.new(
0.5,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut,
0,
true
)
local tween = game:GetService('TweenService'):Create(GUI, info, {Size = GUI.Size + UDim2.new(0, offset_X, 0, offset_Y)})
tween:Play()
end
game:GetService('RunService').RenderStepped:Connect(animate_heart)
The result of this code is that it continuously grows the GUI object without reversing to shrink it. One solution that I don’t want to implement in my code is this:
function animate_heart()
local info = TweenInfo.new(
0.5,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut,
0,
true
)
local tween = game:GetService('TweenService'):Create(GUI, info, {Size = GUI.Size + UDim2.new(0, offset_X, 0, offset_Y)})
tween:Play()
tween.Completed:Wait()
local tween = game:GetService('TweenService'):Create(GUI, info, {Size = GUI.Size - UDim2.new(0, offset_X, 0, offset_Y)})
tween:Play()
end
game:GetService('RunService').RenderStepped:Connect(animate_heart)
I overall think that this is purely bad practice and don’t want to use code like this. Is there any solution to my problem?