How do you make a part move up and down?

Sorry if a topic like this one already exist and I do not know in what category i should put it in.

So I want to make water the problem is that it’s not moving which makes it look weird!
Can you make something a part go up and down?
Ex here:

1 Like

Check this this script will make the water go up and down and if the position of the water is still going up it will not make the part aka water go down till the water stoped like if the old height of the water was like 3 and then 4 then it will not make the water go down till the water stop moving like 3 then 3 then we can start to go down

local part = script.Parent
local amplitude = 1 -- how high it bobs
local speed = 2 -- how fast it bobs
local checkSpeedThreshold = 5 -- how fast it's allowed to move before we pause animation
local baseY = part.Position.Y

local runService = game:GetService("RunService")
local lastPositionY = part.Position.Y
local timeCounter = 0

runService.Heartbeat:Connect(function(dt)
	-- Calculate vertical speed
	local currentY = part.Position.Y
	local velocityY = (currentY - lastPositionY) / dt
	lastPositionY = currentY

	-- Only update animation if not going up too fast
	if velocityY < checkSpeedThreshold then
		timeCounter += dt
		local offset = math.sin(timeCounter * speed) * amplitude
		local newPos = Vector3.new(part.Position.X, baseY + offset, part.Position.Z)
		part.Position = newPos
	else
		-- update baseY so animation resumes smoothly later
		baseY = part.Position.Y
		timeCounter = 0
	end
end)
4 Likes

OMG TYSM it works so well yippee!

1 Like