How would I go about making it look like someone drank a liquid

To get back into roblox coding, I decided to make a game about drinking coffee. I have the coffee model, the actual animation done. But now I’m struggling with how to actually make the illusion it was drank. I decided to go about this, by adding separate little disks in the cup, for an amount of 9, which every time the anim was played, it would delete one. Currently I’m struggling on how I should go about deleting one disk at a time. This is how the entire set up looks. This is an image of the cup with the disks of coffee in it, from the explorer view, and the code for playing the animation in a server script. I did the tool thing obviously by using a local and remote event.

1 Like

How about tweening the specific liquid part to decrease height, and since playing animations and tweens doesn’t pause the script and wait until it’s finished, you could play them at the same time.

It would be better to use one Disk to fill the cup. This way you can create a smoother animation. Try doing something like this:

local model = script.Parent
local cup = model:WaitForChild("Cup")
local disk = model:WaitForChild("Disk")

disk.Size = cup.Size * 0.9
disk.CFrame = cup.CFrame

for i = 0, 1, 0.01 do
	disk.Size = Vector3.new(cup.Size.X * i, cup.Size.Y, cup.Size.Z) * 0.9
	disk.CFrame = cup.CFrame * CFrame.new(disk.Size.X / 2 - cup.Size.X / 2, 0, 0)
	wait()
end

1 Like

Hmmm. I’ll try it later. Kind of busy now, but thanks for the idea.

1 Like

Using a tween is easier and more controllable as well

It is not easier. You will have to construct a new tween instance every time size is updated for the CFrame property because the goal CFrame would need to change every time the Size is updated–it is based off the size.

disk.CFrame = cup.CFrame * CFrame.new(disk.Size.X / 2 - cup.Size.X / 2, 0, 0)

but even without tweens you have to do that as well, but if you use a tween you can easily control time speed color etc

You can also easily change the speed of the “fill” transition. The time it takes to finish is dictated by how many iterations the loop does multiplied by the time each iteration takes.

wait() * (1 - 0) / 0.01 is roughly equal to 0.03 * 100 which is 3 seconds.

A wait call returns how long the function yielded. (1 - 0) represents the range we are iterating over, and 0.01 represents the step per each iteration of that set we are going to iterate over.

compared to a tween where you literally only have to change a single number
also easing styles, reverses, repeats

And the code would have lots of extra bloat–we must construct a new Tween every time the Size parameter is changed–which means you’re either going to be dealing with an event connection, or some other type of loop to accomplish that.

For the most part you also only need to change one number to dictate how long the “fill” will take, but you can change two if you want: the delta per each iteration, or the time the thread yields per iteration. It is not hard to change a number, or two at most.

why? Im pretty sure you only need a single tween

You have ignored everything I’ve said then.

The CFrame property’s value in this case will have to be tied to the Size property so you can offset the Disk by half the height of the disk so that it is positioned properly within the cup. I even highlighted the code.

If you really think that a tween will simplify this process then go ahead and write some code and post it .

local TS = game:GetService("TweenService")

local part = script.Parent
local tInfo = TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1, true, 0)
local goal = {
	Size = Vector3.new(part.Size.X, 0, part.Size.Z),
	CFrame = CFrame.new(part.CFrame.X, part.CFrame.Y - part.Size.Y / 2, part.CFrame.Z)
}

TS:Create(part, tInfo, goal):Play()

one tween

So uh, I tried your way, and my cup just a s c e n d e d. What could I do to fix it? It fills up slowly, which is what I wanted, just the opposite way, but it also decides to go ahead and leave into the sky.

1 Like
local model = script.Parent
local cup = model:WaitForChild("Cup")
local disk = model:WaitForChild("Disk")

disk.Size = cup.Size * 0.9
disk.CFrame = cup.CFrame

for i = 1, 0, -0.01 do
	disk.Size = Vector3.new(cup.Size.X * i, cup.Size.Y, cup.Size.Z) * 0.9
	disk.CFrame = cup.CFrame * CFrame.new(disk.Size.X / 2 - cup.Size.X / 2, 0, 0)
	wait()
end

edit: btw i swapped the things in the for statement