Wrong distance and speed when moving multiple parts

This one works, it moves the part up by five and down by five studs.

When I try moving multiple parts but with the same distance and speed it breaks. When I add or remove parts the distance and speed also change. Even when it’s only moving one part, it still behaves wrong.

i believe this works

local distance = 5
local speed = 2

for _,v in pairs(workspace.Folder:GetChildren()) do
	spawn(function()
		local startPosition = v.Position
		while true do
			local newPosition = startPosition + Vector3.new(0,math.sin(tick() * speed) * distance, 0)
			v.Position = newPosition
			wait(0.01)
		end
	end)
end

also they were going higher because you were setting the startpos every time they moved which made it go to the same position it was at + the movement

1 Like

It’s because on every object iteration, it yields making the last part to get moved not in sync. You need to create a thread for every part, just like what @silas_4008 provided

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