so I’ve been trying to make a knock-off elixir pump, and as a prototype for “collecting” the elixir, the player must touch the valve to collect the elixir when it’s full. Yet from the ‘print(“hit2”)’ and down the code doesn’t work. Any fix?
local db = false
local aether = script.Parent
local i = 0 -- elixir size count
local valve = script.Parent.Parent.Valve.ValveHandle
local finished = false
if i < 10 and finished == false then
for count = 1, 100 do
wait(0.1)
i = i + 0.1
aether.Size = Vector3.new(i, 4.7, 4.7)
if i >= 10 then
finished = true
end
end
end
valve.Touched:Connect(function(hit)
print("hit")
if hit.Name == "ValveHandle" and finished == true then
print("hit2")
for count = 1, 100 do
wait(0.01)
i = i - 0.1
aether.Size = Vector3.new(i, 4.7, 4.7)
end
end
end)
I just don’t get why you don’t just tween the things size in a second using TweenService like for example:
local db = false
local aether = script.Parent
local i = 0 -- elixir size count
local valve = script.Parent.Parent.Valve.ValveHandle
local finished = false
local TweenDown = TweenService:create(aether, TweenInfo.new(1), {Size = {Vector3.new(the size you wanna tween)}
local TweenUp = TweenService:create(aether, TweenInfo.new(1), {Size = {Vector3.new(the size you wanna tween)}
TweenDown:Play()
repeat wait() until TweenDown.Completed
Finished = true
valve.Touched:Connect(function(hit)
if hit.Name== "ValveHandle" and finished == true then -- you know the hit is apart of the player character right?
TweenUp:Play()
repeat wait() until TweenUp.Completed
end
end
I researched a bit and found out part touched event cannot be triggered by tweening IF the part is anchored. Is that true? Forum post
and if it is, is there any way to go around it as simple as possible?
EDIT: I found that now, the problem is “and finished == true” in:
valve.Touched:Connect(function(hit, player)
print("b")
if hit.Parent:FindFirstChild("Humanoid") and finished == true then
print("Character Detected")
TweenUp:Play()
repeat wait() until TweenUp.Completed
end
end)
I’ve done it without “finished == true” and it works.