Problem with CFrame and :MoveTo

Hello everyone,

I have this problem with the move I am working on that includes some teleportation. While making the hitbox I found this problem where the hitbox is on the wrong CFrame when moving and sometimes even without moving.

Watch Bug1 | Streamable (idk why streamable is doing this sorry)

This is the code for the move :

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RemoteEvent = ReplicatedStorage.Events.Remote.ThunderClapRemote
local TweenService = game:GetService("TweenService")
local Player = game:GetService("Players")
local debounce = false


RemoteEvent.OnServerEvent:Connect(function(player)
	if debounce == true  then
		return
	end
	debounce = true
	local HumanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
	local Startpos = HumanoidRootPart.CFrame
	local hitbox = Instance.new("Part")

	hitbox.Parent =workspace.Map 
	hitbox.Color = Color3.new(1, 0, 0)
	hitbox.CanCollide = false
	hitbox.Transparency = 0.8
	hitbox.Anchored = true
	hitbox.Size = Vector3.new(12,5,50)
	hitbox.CFrame = HumanoidRootPart.CFrame + Vector3.new(0,0,-30)
	
	
	local function MakeCount()
		for count =  1 ,5 do
			local X 
			local countfolder = {}
			local part = Instance.new("Part")



			if count % 2 == 0  then
				X = -6
			else
				X = 6
			end

			part.Parent = game.Workspace
			part.Anchored = true
			part.CanCollide = false
			part.Transparency = 1
			part.Size = Vector3.new(1,1,1)
			part.CFrame = Startpos * CFrame.new(0 + X,0,-count * 10)


			player.Character:MoveTo(part.Position)

			wait(0.1)
			part:Destroy()
			
		end
	end
	
	task.spawn(MakeCount)
	task.wait(MakeCount())

	hitbox:Destroy()
	wait(3)
	debounce = false
end)


Thanks for helping!

It should be player.Character.Humanoid:MoveTo. and not player.Character:MoveTo

That broke the script it has nothing to do with the loop.

From what I gather from the video you want the hitbox to be on your left and right 5 times right?

No it is that the hitbox is on the wrong place when i am moving but not when i am standing still. I want to spawn the hitbox inside me but for some reason it doesnt when i am moving or looking the wrong way

I’ll try and solve this for you step by step here
IF you want to spawn the hitbox inside of you, then do not store the cframe of the hmr in a variable. Variables store the cframe of that instant, so if the character moves then the cframe is outdated. So it should be like part.CFrame = HumanoidRootPart.CFrame * CFrame.new(0 + X, 0, -count * 10)