Weld moves player's HumanoidRootPart to Part1's position

Currently, I want to make a wall-run system in my game, and I want to make it so that you attach to the part after pressing Space. However, when I run the script, the player moves to the center of Part1 (Part0 is the humanoid root part, Part1 is the target part), and I have no idea how to patch this. I tried setting the C0 to the target part’s CFrame subtracted by the HumanoidRootPart’s CFrame, but the result was the same (and it errored.)

Here is the code.

if pStat.Vaulting then return end
		if not end_Input then return end
		local ray, side = RaycastLR(5, hrp, false)
		local MAX_TIME = 1
		---
		local function ray_Check()
			repeat
				ray, side = RaycastLR(5, hrp, false)  ----- FIRST RAY CHECK
				MAX_TIME -= 0.1
				if ray then
					break
				end
				if MAX_TIME <= 0 then
					return
				end
				task.wait(0.1)
			until ray
		end
		------
		ray_Check()
		if not pStat.Wallrunning then
			ray_Check()
			if not ray then return end -- failsafe
			pStat.Wallrunning = true
			----
			local instance:Part = ray.Instance
			local dist = instance.Position - hrp.Position
			---
			local new_Weld = Instance.new("Motor6D", hrp)
			new_Weld.Name = "Wallrun_Weld"
			new_Weld.Part0 = hrp
			new_Weld.Part1 = instance
			new_Weld.C0 = (hrp.CFrame - instance.CFrame)
		else
			Cancel_Wall_Run()
			pStat.Wallrunning = false
		end

Again, I don’t know much math and I’m sorry for my bad wording, but any help is appreciated.

Happens pretty often to me, the only solution I can think of is just setting the CFrame of the part to the HumanoidRootPart’s CFrame applying the offset you want and then create the weld and set it up (not sure if this is what you mean, correct me if I’m wrong)

Edit: If the part1 is an anchored wall, then my solution isn’t gonna work. Can’t really think of anything else as I don’t use Welds too much, but I recommend you to use BodyMovers like AlignPosition and AlignOrientation, they are way smoother

Thank you, it works so much better now!

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