Player grabbing issues

I’m attempting to make a grab player feature but it flings the player into the ground. I tried making the player being grabbed sat constantly, but that just made it worse.

Server script:

  game.ReplicatedStorage.Remotes.Grab.OnServerEvent:Connect(function(p,char)
	if not p.Character.Head:FindFirstChild("GrabWeld") then
		for i, v in pairs(game.Players:GetPlayers()) do
			print((v.Character:GetPrimaryPartCFrame().Position - p.Character:GetPrimaryPartCFrame().Position).magnitude)
			if v.Character and v ~= p and v.Character:FindFirstChild("Ragdolled") then
				if (v.Character:GetPrimaryPartCFrame().Position - p.Character:GetPrimaryPartCFrame().Position).magnitude <= 5 then
					local part = v.Character.PrimaryPart
					spawn(function()
						local Grabbed = false
						if not part.Parent:FindFirstChild("Grabbed") then
							local e = Instance.new("StringValue")
							e.Name = "Grabbed"
							e.Parent = part.Parent
						else
							Grabbed = true
						end
						if Grabbed == false then
							local Weld = Instance.new("Weld")
							Weld.Parent = p.Character.Head
							Weld.Part0 = part.Parent.UpperTorso
							Weld.Name = "GrabWeld"
							Weld.Part1 = p.Character.Head
							for i, v in pairs(part.Parent:GetChildren()) do
								if v:IsA("BasePart") then
									v.Massless = true
								end
							end
							spawn(function()
								repeat
									part.Parent.Humanoid.Sit = true
								until not p.Character.Head:FindFirstChild("GrabWeld")
							end)
							part.Parent.Humanoid.JumpPower = 0
							part.Parent.Humanoid.WalkSpeed = 0
							wait(.5)
							p.Character:SetPrimaryPartCFrame(p.Character.PrimaryPart.CFrame.Position*Vector3.new(0,5,0))
						end
					end)
				end
			end
		end
	else
		p.Character.Head.GrabWeld.Part0.Parent.Grabbed:Destroy()
		p.Character.Head.GrabWeld:Destroy()
	end
end)

Any help would be appreciated.:slightly_smiling_face:

2 Likes

Could you post or a more detailed description of what happens when a player tries to grab another player?

I don’t know exactly what’s wrong, but maybe it’s got to do with network ownership of the character models? Network ownership works on entire assemblies of parts, so when you weld one character to another they go from 2 different assemblies to a single one, and it’s not clear which player ends up owning their new “shared” character. Try explicitly setting network ownership of the grabbed character to the grabbing player.

Another thing that might be an issue is setting the properties of the grabbed character (massless, and network ownership if you go with my earlier suggestion) after creating the weld. Maybe suddenly having a heavy (and still massive) model welded to it causes the grabbing character to fling around, even though the grabbed character is set to massless the instant after?

If all else fails, you could replace the grabbed character with a “fake” character model, and create your own custom CameraScript and ControlScript that can handle a special “grabbed” state, where controls are disabled and the camera follows the fake character instead of the real character. When a player becomes ungrabbed, just remove the fake character and put the real character back into workspace, at the same CFrame as the fake one.

1 Like

https://gyazo.com/2098695f8177dc408161ceee30282a69

Maybe I’m wrong but I think you need set C0 and C1 of the weld or that will happen. (Also try swap the Part0 and Part1)

Sorry for the wait. I tried all of your suggestions and nothing worked.