Hello everyone,
I’m making a drinkable and refillable water bottle for a game I’m working on, but I’ve got one problem - the water level in the bottle needs to be able to decrease. I tried a for loop, but it doesn’t quite work. This is because when sizing a part in one direction, you need to change the position by half the increment you’re scaling it by. Therefore, when I move it on the Y axis, it moves slightly off, as I also have a drinking animation that changes the orientation of the part.
Here’s my script:
local tool = script.Parent
local char = nil
local animation = script.Sip
local sipsLeft = script.SipsLeft
local m6d
local tweenService = game:GetService("TweenService")
local waterpart = script.Parent.Tool.Water
local sizes = {
[0] = Vector3.new(0, 0.4, 0.56),
[1] = Vector3.new(0.45, 0.4, 0.56),
[2] = Vector3.new(0.95, 0.4, 0.56),
[4] = Vector3.new(1.25, 0.4, 0.56)
}
tool:GetPropertyChangedSignal("Parent"):Connect(function()
if char then
return
end
if tool.Parent.Name == "Backpack" then
char = tool.Parent.Parent.Character
end
end)
tool.Equipped:Connect(function()
local a:Weld = char:FindFirstChild("Right Arm"):WaitForChild("RightGrip")
m6d = Instance.new("Motor6D")
m6d.Parent = char:FindFirstChild("Right Arm")
m6d.Name = "RightGrip"
m6d.Part0 = a.Part0
m6d.Part1 = a.Part1
m6d.C0 = a.C0
m6d.C1 = a.C1
a:Destroy()
end)
tool.Unequipped:Connect(function()
m6d:Destroy()
end)
tool.Activated:Connect(function()
if sipsLeft.Value > 0 then
sipsLeft.Value -= 1
local animator = char:WaitForChild("Humanoid").Animator
local load = animator:LoadAnimation(animation)
load:Play()
for i = 1, 125 do
local cur = waterpart.Size
local curpos = waterpart.Position
waterpart.Size = Vector3.new(cur.X-0.004, cur.Y, cur.Z)
waterpart.Position = Vector3.new(curpos.X, curpos.Y-0.002, curpos.Z)
task.wait()
end
print("Played animation,", sipsLeft.Value, "sips left")
else
print("No water left!")
return
end
end)
Is there any alternative to a for loop, or any way to change the script to move the part along its local axis?