How do I Weld the player's character to a part?

Hello. So I have this van model in my game and I’ve been trying to weld the player to the van in order to move the player with the van. (Van is moving via tween) But what happens instead is the player just starts floating in the air and not even moving with the van.
Any idea of how I could do this?

Sorry if this is the wrong category to ask this in.

I’ve tried this script to weld the player’s Left Foot to the van:

local Weld = Instance.new("WeldConstraint", hit.Parent.LeftFoot)
Weld.Part0 = hit.Parent.HumanoidRootPart
Weld.Part1 = game.Workspace.Van.VanBody
Weld.Name = "VanWeld"

By the way this is in a Touched-hit event

Thanks!

2 Likes

Why would you use weld ? It is mainly used with mech parts, with players, try keeping track of player position and van position

2 Likes

Would I Tween the Player’s CFrame to match the van’s Tween?
I thought of something like that but I wasn’t sure how that would work if there were multiple people in the van.
Sorry if the solution is obvious.

1 Like

It may not be the smoothest van ever but you’ll want to weld every part in the van to its primary part, then weld the primary part to the left foot. That way everything is attached and follows the primary part. You can create a loop script to weld every part in the van and either put it in the cmd bar or in a script.

Here is the script to save time:

local function WeldModelToPrimary(Part1)
		for i, part in pairs(Part1:GetDescendants()) do
			if part:IsA("BasePart") and part ~= Part1.PrimaryPart then
				local weld = Instance.new("WeldConstraint")
				weld.Part0 = part
				weld.Part1 = Part1.PrimaryPart
				weld.Parent = part
			end
		end
	end
WeldModelToPrimary(workspace.Van) --Keep in mind to make the van body the primary part

Also, this is deprecated:

local Weld = Instance.new("WeldConstraint", hit.Parent.LeftFoot)

Do this instead

local Weld = Instance.new("WeldConstraint")
Weld.Parent = hit.Parent.LeftFoot
1 Like

That might work. Except that the van is one Union. I could make the Union the primary part to see if that would work. I’ll try that later and get back to you.
Thanks!

1 Like

I also forgot that you need to set the vans CFrame to the character. Also, whatever body part you attach the weld to is what the van will follow. You set it to the humanoid root part, but the parent to the left foot.

local Weld = Instance.new("WeldConstraint")
Weld.Part0 = hit.Parent.HumanoidRootPart
Weld.Part1 = game.Workspace.Van.VanBody
Weld.Name = "VanWeld"
Weld.Parent = hit.Parent.HumanoidRootPart

workspace.Van.VanBody.CFrame = hit.Parent.HumanoidRootPart.CFrame

If it doesn’t work try setting the CFrame before attaching the weld. Another thing, make sure nothing is the van is anchored.

1 Like

I need the van to be anchored or else it’s going to start moving in ways I don’t want.

I also tried the code and it didn’t work. And yes I also tried changing the van’s CFrame before making the weld. That also didn’t work.

Welds won’t work if the part is anchored because you’re character will be anchored along with it. I’m not sure why it still isn’t working what exactly is happening?

1 Like

Here is a video of me testing it.

robloxapp-20210707-1635198.wmv (2.6 MB)

Edit: I didn’t mean to send it as a download link

robloxapp-20210707-1635198.wmv (2.6 MB)

EDIT: Oh for crying out loud…sorry

Oh I see, I thought you wanted to make the van follow the player. An easier way to do this is to have multiple seats/parts and just weld the player to those parts. Also, instead of setting the Van’s CFrame you’ll want to set the HumanoidRootPart’s CFrame to the van or seat.

1 Like

So would I have a unanchored part(s) welded to the van and weld the HumanoidRootPart to the part(s)?

Almost, you’ll want anchored parts welded to the van. Then weld the HumanoidRootPart to those parts and set the CFrame. They have to be anchored so the player cant move.

3 Likes

So by “Set the CFrame” do you mean constantly changing the anchored part’s CFrame to the van’s CFrame?
Sorry.

EDIT: I tried that and it worked perfectly! Thank you so much for you help! (And sorry for confusing you lol.)
Thanks!!

1 Like

No problem. You can weld the seats to the van so they stay instead of constantly changing them. By set the cframe I mean set the humanoid root part’s cframe to seat once, then weld.

Oh ok. I think the way I have it will work fine. But thanks!

Thank you so much for the help!

1 Like