Welding part to humanoid causes player to teleport

As the title says, whenever I weld the part to the humanoid, it weirdly causes the player to teleport around. I am attempting to make a hitbox using spatial queries. This is a local script stored in StarterCharacterScripts

local players = game:WaitForChild("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()
local humanoid = script.Parent:FindFirstChild("Humanoid")
local humanoidRootPart = humanoid.RootPart

local offset = Vector3.new(2,0,0)

local UserInputService = game:GetService("UserInputService")


function newHitbox ()
	local weld = Instance.new("WeldConstraint", humanoidRootPart)
	local hitbox = Instance.new("Part")
	weld.Parent = humanoidRootPart
	weld.Part0 = humanoidRootPart
	weld.Part1 = hitbox
	
	hitbox.Massless = true
	hitbox.Transparency = 0
	hitbox.CanCollide = false
	hitbox.CanQuery = false
	hitbox.Size = Vector3.new(5, 5, 5)
	hitbox.Parent = player.Character
	hitbox.CFrame = humanoidRootPart.CFrame + humanoidRootPart.CFrame.LookVector * offset.X + Vector3.new(0,offset.Y)
end

I’m a novice at coding, but I’ve looked through other posts here with similar problems, though any solutions don’t seem to work for me. Thank you in advance!

Notice how you’re changing the part’s properties after welding it to the HumanoidRootPart. I believe it can be fixed by simply changing the part’s properties before welding it.

Also, it’s recommended to change any property of a BasePart before parenting it to the Workspace. There you are changing the part’s CFrame after parenting it unecessarily. Read this post for more information:

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