How to make pump collect work only AFTER it is full?

so I got a knockoff elixir pump that I made. The liquid has a tween function that, when ends, should make you manually collect the elixir by touching a valve.

Problem is, you can collect the elixir even if it’s not fully done yet. I also had a version where, if you touched it while it was not done, it waited until it was done and then collected it automatically (which I don’t want to happen)

so How do I make it collect only after the tween is done?

	--/ Variables & Services
	local aether = script.Parent
	local valve = script.Parent.Parent.Valve.ValveHandle
	local refillTime = 5 -- How much it takes to refill it
	local aetherValue = 5 -- How much Aether can it store

	local TweenService = game:GetService("TweenService")

	local TweenDown = TweenService:Create(aether, TweenInfo.new(1), {Size = Vector3.new(0.1, 4.7, 4.7)})

	local TweenUp = TweenService:Create(aether, TweenInfo.new(refillTime), {Size = Vector3.new(10, 4.7, 4.7)})

	--/ Main gameloop
	TweenDown:Play()
	repeat wait() until TweenDown.Completed
	TweenUp:Play()
	repeat wait() until TweenUp.Completed

	valve.Touched:Connect(function(hit)
		if TweenUp.Completed then
			if hit.Parent:FindFirstChild("Humanoid") and TweenUp.Completed then
				print("Character Detected")
				repeat wait() until TweenUp.Completed
				TweenDown:Play()		
			end
		end
	end)

	TweenDown.Completed:Connect(function()
		wait(5)
		TweenUp:Play()
	end)

Example video: Imgur: The magic of the Internet
The pump is not supposed to be collected before it finishes.

The problem is, after the first time, the Touched function will still run and it will restart. So, disconnect the touched function after it is touched.

--/ Variables & Services
	local aether = script.Parent
	local valve = script.Parent.Parent.Valve.ValveHandle
	local refillTime = 5 -- How much it takes to refill it
	local aetherValue = 5 -- How much Aether can it store

	local TweenService = game:GetService("TweenService")

	local TweenDown = TweenService:Create(aether, TweenInfo.new(1), {Size = Vector3.new(0.1, 4.7, 4.7)})

	local TweenUp = TweenService:Create(aether, TweenInfo.new(refillTime), {Size = Vector3.new(10, 4.7, 4.7)})

	--/ Main gameloop
	TweenDown:Play()
	repeat wait() until TweenDown.Completed
	TweenUp:Play()
	repeat wait() until TweenUp.Completed

    local tconn

	tconn = valve.Touched:Connect(function(hit)
		if TweenUp.Completed then
			if hit.Parent:FindFirstChild("Humanoid") and TweenUp.Completed then
				print("Character Detected")
                tconn:Disconnect()
				TweenDown:Play()		
			end
		end
	end)

	TweenDown.Completed:Connect(function()
		wait(5)
		TweenUp:Play()
	end)
--//Tables
local Connections = {}

--/ Variables & Services
local aether = script.Parent
local valve = aether.Parent.Valve.ValveHandle
local refillTime = 5 -- How much it takes to refill it
local aetherValue = 5 -- How much Aether can it store

local TweenService = game:GetService("TweenService")

local TweenDown = TweenService:Create(aether, TweenInfo.new(1), {Size = Vector3.new(0.1, 4.7, 4.7)})

local TweenUp = TweenService:Create(aether, TweenInfo.new(refillTime), {Size = Vector3.new(10, 4.7, 4.7)})

--/ Main gameloop
TweenDown:Play()
TweenDown.Completed:Wait()

TweenUp:Play()
TweenUp.Completed:Wait()

Connections["Touched"] = valve.Touched:Connect(function(hit)
	if TweenUp.Completed then
		if hit.Parent:FindFirstChild("Humanoid") and TweenUp.Completed then
			TweenDown:Play()
			
			Connections["Touched"]:Disconnect()
		end
	end
end)

TweenDown.Completed:Connect(function()
	task.wait(5)
	TweenUp:Play()
end)

Well, isn’t this just a simple if statement?

		if TweenUp.Completed **and aether.Size = Vector3.new(10, 4.7, 4.7)** then
			if hit.Parent:FindFirstChild("Humanoid") and TweenUp.Completed then
				print("Character Detected")
				repeat wait() until TweenUp.Completed
				TweenDown:Play()		
			end
		end

The simplest solution I found. Also, for anybody wanting to do something similar, remove the ** and change the “xx.size = Vector3.new” to have == instead of =

1 Like