Trying to make drink slowly empty out

Hi, I’m Blame.

I’m trying to make a simple script where it would allow you to take 4 sips of the cup, and whatever is inside the cup will slowly go down until the cup is empty, the issue is that when trying to tween the size, it ends up going to the middle of the cup and not the bottom. Also it doesn’t change the size when sipstaken is 2-3 (I think, because when it prints nothing happens and it says the number went up one)

Thanks in advance!

CODE:



local TweenService = game:GetService("TweenService")
debounce = false
sipstaken = 0
sipsallowed = 4
local part = script.Parent.Filling



script.Parent.Activated:Connect(function()
	
	
	if not debounce then
		
		
		
		if sipstaken >= sipsallowed then
			local Goal4 = {Size = Vector3.new(0.173, 0.67, 0.71)}
			local tweenInfo4 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
			local Tween4 = TweenService:Create(part, tweenInfo4, Goal4)
			part.Position = Vector3.new(17.995, 2.689, -0.555)
			Tween4:Play()
			Tween4.Completed:Wait()
			script.Parent.Name = "Empty Regular Size"
		else
			
			
			
			
			debounce = true
			sipstaken = sipstaken + 1
			print(sipstaken)
			
			
			
			
			if sipstaken == 1 then
				local GoalOne = {Size = Vector3.new(0.523, 0.67, 0.71)}
				local tweenInfo1 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
				local Tween1 = TweenService:Create(part, tweenInfo1, GoalOne)
				part.Position = Vector3.new(17.995, 2.884, -0.555)
				Tween1:Play()
				Tween1.Completed:Wait()
			end
			
			if sipstaken == 2 then
				local GoalTwo = {Size = Vector3.new(0.544, 0.67, 0.71)}
				local TweenInfo2 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
				local Tween2 = TweenService:Create(part, TweenInfo2, GoalTwo)
				part.Position = Vector3.new(17.995, 2.866, -0.555)
				Tween2:Play()
				Tween2.Completed:Wait()
			end
			
			if sipstaken == 3 then
				local GoalThree = {Size = Vector3.new(0.366, 0.67, 0.71)}
				local TweenInfo3 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
				local Tween3 = TweenService:Create(part, TweenInfo3, GoalThree)
				part.Position = Vector3.new(17.995, 2.812, -0.555)
				Tween3:Play()
				Tween3.Completed:Wait()
			end
			wait(1)
			
			debounce = false
			
			end
	end
end)

Gif of issue:
https://gyazo.com/c6b9cdfbf4978f21482c9eb19ba95869

2 Likes
local TweenService = game:GetService("TweenService")
local debounce = false
local sipstaken = 0
local sipsallowed = 4
local part = script.Parent.Filling



script.Parent.Activated:Connect(function()
	
	
	if debounce ~= true then
		
		
		
		if sipstaken >= sipsallowed then
			local Goal4 = {Size = Vector3.new(0.173, 0.67, 0.71)}
			local tweenInfo4 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
			local Tween4 = TweenService:Create(part, tweenInfo4, Goal4)
			part.Position = Vector3.new(17.995, 2.689, -0.555)
			Tween4:Play()
			Tween4.Completed:Wait()
			script.Parent.Name = "Empty Regular Size"
		else
			
			
			
			
			debounce = true
			sipstaken = sipstaken + 1
			print(sipstaken)
			
			
			
			
			if sipstaken == 1 then
				local GoalOne = {Size = Vector3.new(0.523, 0.67, 0.71)}
				local tweenInfo1 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
				local Tween1 = TweenService:Create(part, tweenInfo1, GoalOne)
				part.Position = Vector3.new(17.995, 2.884, -0.555)
				Tween1:Play()
				Tween1.Completed:Wait()
			end
			
			if sipstaken == 2 then
				local GoalTwo = {Size = Vector3.new(0.544, 0.67, 0.71)}
				local TweenInfo2 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
				local Tween2 = TweenService:Create(part, TweenInfo2, GoalTwo)
				part.Position = Vector3.new(17.995, 2.866, -0.555)
				Tween2:Play()
				Tween2.Completed:Wait()
			end
			
			if sipstaken == 3 then
				local GoalThree = {Size = Vector3.new(0.366, 0.67, 0.71)}
				local TweenInfo3 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
				local Tween3 = TweenService:Create(part, TweenInfo3, GoalThree)
				part.Position = Vector3.new(17.995, 2.812, -0.555)
				Tween3:Play()
				Tween3.Completed:Wait()
			end
			wait(1)
			
			debounce = false
			
			end
	end
end)

(Sorry for late reply) Didn’t work, caused same issue.

Tween size tween from both length. Maybe you got to try something to make it tween only 1 side.

There isn’t a way to tween from one side, I’ve tried that.

You can use lerping, it’s also called linear interpolation, watch DevKing video on it and it should help you, you can use it to make it go a percentage of the way to a destination, for example only 1/4 or 25% of the way to the bottom of the cup, and then do on

2 Likes

Will try this later today, if works I’ll mark you as solution :slight_smile:

1 Like

I don’t think this will work, simply because if I try to Lerp the drink inside the cup, it’ll be the full part, I don’t think you can Lerp the size, unless I’m wrong.

EDIT: After doing testing, I guess you can! LOL should’ve known.

If you want to change position of a instance that is in effect of joints (weld etc), you have to do it through joint’s C0 or C1 properties.

What you wanna do is decrease size by Filling’s size divided by maximum amount of sips and decrease joint’s C1 by Vector3.new((FillingStartSize/MaximumSips)/2,0,0) every time player takes a sip.

I made a script that might be useful if you try to understand it.

local Filling,Handle = script.Parent:WaitForChild("Filling"),script.Parent:WaitForChild("Handle")
local Joint = nil

--So here, script tries to find the joint.
for _,v in pairs(Handle:GetChildren()) do
	if (v:IsA("Weld") or v:IsA("Motor6D")) and (v.Part1 == Filling or v.Part0 == Filling) then
		Joint = v
	end
end

--If it was unable to find it, it creates one.
if not Joint then 
	Joint = Instance.new("Weld")
	Joint.Part0 = Handle
	Joint.Part1 = Filling
	Joint.C0 = Handle.CFrame:toObjectSpace(Filling.CFrame)
	Joint.C1 = CFrame.new()
	Joint.Parent = Handle
end

local function Tween(instance,tweentime,properties) --It makes tweening easier
	local a = game:GetService("TweenService"):Create(instance,TweenInfo.new(tweentime),properties)
	a:Play()
	delay(tweentime+.1,function()
		a:Destroy()
	end)
	return a
end

local SipTaken = 0 --Sips taken so far
local SipAmount = 4 --Maximum amount of sips

local DecreasePerSip = Filling.Size.X/SipAmount --Finding out how much to decrease per sip

local TweenTime = 2 
local v3 = Vector3.new --Just using some shortcuts
local Debounce = false

script.Parent.Activated:Connect(function()
	if Debounce then return end
	if SipTaken >= SipAmount then return end
	Debounce = true
	SipTaken += 1 --Increase taken sips
	
	if game:GetService("RunService"):IsStudio() then print(SipTaken) end --Some debugging
	
	Tween(Filling,TweenTime,{Size=v3(Filling.Size.X-DecreasePerSip,Filling.Size.Y,Filling.Size.Z)})
	
	Tween(Joint,TweenTime,{C1=Joint.C1-v3(DecreasePerSip/2,0,0)})
	
	delay(TweenTime,function()
		Debounce = false
	end)
end)

I’ll try this in a second, if this Lerp method doesn’t work ill resort to this.

Try this:

local TweenService = game:GetService(“TweenService”)
debounce = false
sipstaken = 0
sipsallowed = 4
local part = script.Parent.Filling

script.Parent.Activated:Connect(function()

if not debounce then

  if sipstaken >= sipsallowed then
  	local Goal4 = {Size = Vector3.new(0.173, 0.67, 0.71)}
  	local tweenInfo4 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
  	local Tween4 = TweenService:Create(part, tweenInfo4, Goal4)
  	part.Position = Vector3.new(17.995, 2.689-(part.Size/2), -0.555)
  	Tween4:Play()
  	Tween4.Completed:Wait()
  	script.Parent.Name = "Empty Regular Size"
  else
  	
  	debounce = true
  	sipstaken = sipstaken + 1
  	print(sipstaken)
  	
  	if sipstaken == 1 then
  		local GoalOne = {Size = Vector3.new(0.523, 0.67, 0.71)}
  		local tweenInfo1 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
  		local Tween1 = TweenService:Create(part, tweenInfo1, GoalOne)
  		part.Position = Vector3.new(17.995, 2.884-(part.Size/2), -0.555)
  		Tween1:Play()
  		Tween1.Completed:Wait()
  	end
  	
  	if sipstaken == 2 then
  		local GoalTwo = {Size = Vector3.new(0.544, 0.67, 0.71)}
  		local TweenInfo2 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
  		local Tween2 = TweenService:Create(part, TweenInfo2, GoalTwo)
  		part.Position = Vector3.new(17.995, 2.866-(part.Size/2), -0.555)
  		Tween2:Play()
  		Tween2.Completed:Wait()
  	end
  	
  	if sipstaken == 3 then
  		local GoalThree = {Size = Vector3.new(0.366, 0.67, 0.71)}
  		local TweenInfo3 = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
  		local Tween3 = TweenService:Create(part, TweenInfo3, GoalThree)
  		part.Position = Vector3.new(17.995, 2.812-(part.Size/2), -0.555)
  		Tween3:Play()
  		Tween3.Completed:Wait()
  	end
  	wait(1)
  	
  	debounce = false
  	
  	end
  end

end)

1 Like

Doesn’t work, with the error “Invalid Argument #1, Vector3 expected, got number.”

In wich line of code? I need to know this.

The error is on line 19. Pretty sure because the math you tried doing errored out I think I dunno.

Wich script did you use when you got this error.

What do you mean? I don’t understand. If you’re talking about the type of script, I’m using a regular one not a local one.

You used my script, your script or another script?

I used your script, the one you sent in this thread.