Touched event causes the model to fly erratically

I have speed boosts in my game. Uou gain some speed when you touch them. And i added a floating script to look them smoothier

local model = script.Parent

local distance = 0.2
local speed = 0.05

while true do
	--wait(0.1)
	
	for i = 1, distance / speed do
		local hedefpos = model.Yuzey.Position + Vector3.new(0, speed, 0)
		model:MoveTo(hedefpos)
		wait(0.1) 
	end
	
	wait(0.1)
	
	for i = 1, distance / speed do
		local hedefpos = model.Yuzey.Position - Vector3.new(0, speed, 0)
		model:MoveTo(hedefpos)
		wait(0.1) 
	end
	
	wait(0.1)
end

But when player touches the model while one of the childrens has connected with touched event, the model teleports somewhere very high. Its still happens if i even left the touched function empty

You said:

"Its still happens if i even left the touched function empty”

Is the model anchored?

yeah model is anchored, should i unanchor it?

Based on the documentation for Model:MoveTo(), if there is an obstruction/collision within the area that the model is moving to, the method will instead move the model up until it is no longer obstructed/colliding.

Instead, I suggest using Model:PivotTo() to accomplish this, since this method ignores collisions. Model:PivotTo() accepts an argument of the target CFrame to move the object to. In this case, you can just use CFrame.new(position: Vector3) to create the necessary CFrame values.

I also suggest using math.sin(x) if you want to create an upwards-downwards floating animation. Since a sine wave is periodic, it repeats its uniform wave pattern from [-1, 1] every 2 * pi. You can implement this into your code by setting an origin position/CFrame of the coin, then adding math.sin(time) to it. Here’s what it would look like:

local model = script.Parent
local distance = 0.2
local speed = 0.05
local origin = model:GetPivot()

local secondsToReach = distance/speed

while task.wait(0.1) do
 local yOffset = math.sin((tick()*math.pi*0.5)/secondsToReach)*distance -- Normalize function to hit 1, 0, -1, 0 every 1 second, then divide that by the seconds to reach the distance with the current speed. Afterwards multiply final value by distance to get the actual distance travelled.
 local finalOffset = origin*CFrame.new(0, yOffset, 0)
 model:PivotTo(finalOffset)
end

Graph of base sine wave (math.sin(x)):

Hope this all helps! Let me know if you had any questions.

Edited to fix a small error I made in the code.