Scaling object from different origin

image

This is my tool, when activated I want it to scale drink down, then move it back to the bottom of the cup again (like it’s being drank). At the moment, my script is not moving it down far enough, so theres a gap at the bottom of the cup after ~2 sips. Any help is appreciated!

local tool = script.Parent
local drink = tool:WaitForChild("Drink")
local cup = tool:WaitForChild("Handle")

local scaleDecrement = 0.1 
local activationCount = 0 

local function onActivated()
    if tool.Name == "Cup" then
        print("Cup not filled!")
        return
    end

    local newSize = Vector3.new(
        math.max(drink.Size.X - scaleDecrement, 0), 
        drink.Size.Y,
        drink.Size.Z
    )
    
    drink.Size = newSize

    local cupBottom = cup.Position.Y - (cup.Size.Y / 2)
    drink.Position = Vector3.new(
        drink.Position.X,
        cupBottom + (drink.Size.Y / 2),
        drink.Position.Z
    )

    activationCount += 1

    if activationCount >= 5 then
        drink.Transparency = 1
        tool.Name = "Cup"
    end
end

tool.Activated:Connect(onActivated)

I tried out this code as well and it does not work

drink.Size -= Vector3.new(scaleDecrement, 0, 0)
drink.CFrame *= CFrame.new(-scaleDecrement/2, 0, 0)

please send video

character limit

what im seeing right now is that you arent using the scaled value in the vector for repositioning the cup to where it should be

 local newSize = Vector3.new(
        math.max(drink.Size.X - scaleDecrement, 0), 
        drink.Size.Y,
        drink.Size.Z
    )
    
    drink.Size = newSize

    local cupBottom = cup.Position.Y - (cup.Size.Y / 2)
    drink.Position = Vector3.new(
        drink.Position.X,
        cupBottom + (drink.Size.Y / 2), --why no X lol
        drink.Position.Z
    )

so try replacing that with a x

This video is using the updated script, still not working.

it looks like (to me) that the cup’s bottom isnt being properly set, can you try to put a temporary part there to see if its actually at the bottom of the cup

(create a 1x1 red cube and position it where the cup’s bottom is)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.