Change way things are being welded?

I have these scripts

server:


local event = script.Parent.Shoot
local dropRight = script.Parent.DropRight

local rightHand = script.Parent.HandR
local TS = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

local RightAttached = false
local RightSate = "Stretched"
local LeftAttached = false

local AwaitingRightTouch = true

local RightHolding = false

local PartRightTouch
local PartLeftTouch

local weld = script.Parent.HandR.Grab

local inAnimation = false

event.OnServerEvent:Connect(function(player, side, target)
	if side == "Right" and RightHolding == false then
		if RightAttached == false then
			local Tween = TS:Create(rightHand, tweenInfo, {Position = target})
			Tween:Play()
			Tween.Completed:Wait()
	
			local touchedConnection

			touchedConnection = rightHand.Touched:Connect(function(hit)
				if hit and hit.Anchored == false and hit:GetAttribute("Grabable") == true and not MasterDB then
					print("first")
					AwaitingRightTouch = false
					RightSate = "Stretched"
					weld.Part0 = hit
					hit.Massless = true
					hit.CanCollide = false
					RightAttached = true
					RightHolding = true
					PartRightTouch = hit

					
					touchedConnection:Disconnect()
				else
					task.wait(0.1)
					if AwaitingRightTouch == true then
						AwaitingRightTouch = false
						print("sub")
						local Tween = TS:Create(rightHand, tweenInfo, {Position = script.Parent.PosR.Position})
						Tween:Play()
						Tween.Completed:Wait()
						RightAttached = false
						AwaitingRightTouch = true
						rightHand.Position = script.Parent.PosR.Position
					end
				end
			end)
		end
	elseif RightAttached == true and RightSate ~= "Holding" then
		print("second")
		RightSate = "Holding"
		local Tween = TS:Create(rightHand, tweenInfo, {Position = script.Parent.PosR.Position})
		Tween:Play()
		Tween.Completed:Wait()
		rightHand.Position = script.Parent.PosR.Position
	end
end)

dropRight.OnServerEvent:Connect(function()
	MasterDB = true
	PartRightTouch.Massless = false
	PartRightTouch.CanCollide = true
	weld.Part0 = nil
	if RightSate == "Holding" then
		PartRightTouch.Position = script.Parent.PosR.Position
	else
		PartRightTouch.Position = rightHand.Position
	end
	
	rightHand.Position = script.Parent.PosR.Position
	task.wait(1)
	RightAttached = false
	RightHolding = false
	AwaitingRightTouch = true
	PartRightTouch = ""
	RightSate = ""
	MasterDB = false
end)

client:

local UIS = game:GetService("UserInputService")
local tool = script.Parent
local player = game.Players.LocalPlayer

local event = script.Parent.Shoot
local dropRight = script.Parent.DropRight

local rightHand = script.Parent.HandR

local equipped = false

tool.Equipped:Connect(function()
	equipped = true
end)

tool.Unequipped:Connect(function()
	equipped = false
end)

UIS.InputBegan:Connect(function(input)
	if input and input.KeyCode == Enum.KeyCode.E and equipped == true then
		print("E PRESSED")
		local mouse = player:GetMouse()
		
		local target = mouse.Hit.Position
		local Distance = (mouse.Hit.Position - player.Character.HumanoidRootPart.Position).Magnitude
		
		if not mouse.Target or Distance >= 40 then return end
		
		
		event:FireServer("Right", target)
	else if input and input.KeyCode == Enum.KeyCode.F and equipped == true then
			dropRight:FireServer()
		end
	end
end)

These are making a sort of grabbing system, where the hand that shoots from your character (its a part within a tool) welds onto a part and if it matches some criteria it sticks and you can move it, drop it, or drag it in. This works however not the way i want it to.

Currently it just uses welds, this means if I hid the part in the top right hand corner the whole part will teleport to that the hit position in the top right hand corner is not the center of the part. To which it will not weld. Also if the part is big and i pull it in, it will be inside the players character and look weird.

Weld constraints give me the desired result however you cannot Tween parts welded together using weld constraints with CFrame. which is what i need so that the parts welded would actually move along with the hand.

I’m asking if there is a way i can get my desired result, which is welding such as with Weld Constraints but also to keep the ability to tween using CFrame. I might also add that both parts, the hand and the part it welds to will always be unanchored

Any help is appreciated

2 Likes

With Welds when you apply Part0 and Part1 it automatically centers the 2 together.
weld.C0 and weld.C1 are the Properties you are probably looking for. They are the offsets of the welds.
You can set one (let’s say you used C0) to be the center of the hand and C1 to be the offset required, then tween C1 (minus the distance you want to keep the two items apart) to C0.

Would it automatically weld to where the part was hit or do I need to calculate that somehow.

Also would it still weld to the middle, thus inside of the part or on the surface of it

I never worked with things like this so I don’t know much about it

If you look at the C0 and C1 properties of a Weld you’ll see they both have an Offset (x,y,z).
You’d have to calculate this from the start, which isn’t difficult.
I usually set the first Offset using the C0.
In Studio when the weld is active manually change the C0 values and the item will visibly move to that starting Offset.
I then find the second Offset by changing the C1 values.
Now when you tween C1 you can set it’s original Offset to 0,0,0 and the new Offset to whatever works for you.

The arm is dynamic. You can shoot it anywhere you want, it can hit all locations of a part wouldn’t the offset be different each time

You could make the offset any Position you want it to be at, just change the final position of the tween.
I’m not sure of the math involved with calculating the Offset dependent of the Position you want it to end up though.