Help with welding player to player

Hello, Developers!
I’ve been working on a game and I’m having a bit of a problem with this script:

    local Player1 = game.Players:WaitForChild("Player1")
local Player2 = game.Players:WaitForChild("Player2")
 
script.Parent.Activated:Connect(function()
   
    local Weld = Instance.new("Weld", Player2.Character.HumanoidRootPart)
    Weld.Part0 =   Player1.Character.HumanoidRootPart
    Weld.Part1 =  Player2.Character.HumanoidRootPart
   
   
   
end)

In this script, I’m trying to weld Player2’s HumanoidRootPart to Player1’s HumanoidRootPart by activating a tool. Unfortunately, sometimes it doesn’t work this way and the Welded parts are switched (meaning Player1 gets welded to Player2).

I’ve tried switching it (Part0 with Part1 and putting the weld instance into Player1) in the script, but that didn’t help.

Can you please help me with this? Every suggested solution is appreciated.

9 Likes

Welding two players together is going to be tricky. Roblox physics among other things, especially regarding exploiters, would probably make the player experience a bit subpar. In my personal opinion, it isn’t worth the hassle to implement and I’d definitely try and go for some different mechanic.

What exactly are you trying to accomplish with welding two players together?

3 Likes

A player that can physically carry another player.

1 Like

Perhaps this may be because you’re not setting the C0 and C1 properties of the weld?

Every time I script welds I not only set Part0 and Part1, but also C0 and C1, ever since I watched PeasFactory’s video on it, as such:

local Weld = Instance.new("Weld", Player2.Character.HumanoidRootPart)
Weld.Part0 = Player1.Character.HumanoidRootPart
Weld.Part1 = Player2.Character.HumanoidRootPart
Weld.C0 = Player1.Character.HumanoidRootPart.CFrame:inverse()
Weld.C1 = Player2.Character.HumanoidRootPart.CFrame:inverse()

Not really sure, but whenever I used to script welds without setting C0 and C1, both welded parts would be in their opposite location, hence the :inverse() on their CFrames.

3 Likes

An interesting mechanic, although depending on the game concept you could probably replace that with something else. Perhaps the player who was originally going to be picked up could crawl or something similar. You really don’t want the gameplay to be super reliant on Roblox physics.

I’ve put some code together that seems to get the job done, apply it however you feel necessary and modify it to fit your needs.

local ps=game:GetService("PhysicsService")

ps:CreateCollisionGroup("nocol")
ps:CollisionGroupSetCollidable("nocol","nocol",false)

local function weldPlayers(origin,carry)
	local ro,rc=origin.Character.Head,carry.Character.PrimaryPart
	carry.Character.Humanoid.PlatformStand=true
	local w=Instance.new("Weld")
	w.Name="__CARRYWELD"
	w.Part0=rc
	w.Part1=ro
	w.C1=CFrame.new(0,0,1.75)
	w.Parent=rc
	for _,v in pairs(carry.Character:GetChildren()) do
		if v:IsA("BasePart") then
			ps:SetPartCollisionGroup(v,"nocol")
			v.Massless=true
		end
	end
	for _,v in pairs(origin.Character:GetChildren()) do
		if v:IsA("BasePart") then
			ps:SetPartCollisionGroup(v,"nocol")
		end
	end
end

local function restorePlayer(plr)
	plr.Character.Humanoid.PlatformStand=false
	if plr.Character.PrimaryPart:FindFirstChild("__CARRYWELD") then
		plr.Character.PrimaryPart.__CARRYWELD:Destroy()
	end
	for _,v in pairs(plr.Character:GetChildren()) do
		if v:IsA("BasePart") then
			v.CollisionGroupId=0
			v.Massless=false
		end
	end
end
--[[
 // first player is carrying, second player being carried
weldPlayers(game.Players.Player1,game.Players.Player2)

 // run to reset any existing welds, platformstand state and reset collision
restorePlayer(game.Players.Player1)
restorePlayer(game.Players.Player2)

--]]
25 Likes

That did it. Thanks a lot, Xonae!

1 Like

I’ve tried that, but it didn’t work.

1 Like