Welds shooting item in random directions

I am making a vr grabbing script and every time I try to weld the item has a huge offset. Any help?

local grab = game.ReplicatedStorage.Grab

grab.OnServerEvent:Connect(function(plr, item, grabtype)
	if grabtype == "grab" then
		item.Parent = plr.Character
		local weld = Instance.new("Weld")
		
		local ra = plr.Character:FindFirstChild("RightHand")
		item.PrimaryPart.Anchored = false
		
		weld.Parent = ra
		weld.Part0 = ra
		weld.Part1 = item.PrimaryPart
		
		weld.C0 = weld.Part0.CFrame:Inverse()
		weld.C1 = weld.Part1.CFrame:Inverse()
		
		weld.Name = "VRWeld"
	else
		item.Parent = game.Workspace
		item.PrimaryPart.Anchored = true
		
		local VRweld = plr.Character:FindFirstChild("RightHand"):FindFirstChild("VRWeld")
		if VRweld then
			VRweld:Destroy()
		end
	end
end)
1 Like

It’d probably be easier and shorter to use a weld constraint (unless you specifically need the c0 and c1)

2 Likes

there is even more offset with a weld constraint its really wierd

1 Like

You’d need to parent it after setting the position

what do you mean by this?
dsadsa

Parent the weld after setting the position of the item to the hand

does not seem to make a difference

		item.Parent = plr.Character
		local weld = Instance.new("WeldConstraint")
		
		local ra = plr.Character:FindFirstChild("RightHand")
		item.PrimaryPart.Anchored = false
		
		weld.Part0 = ra
		weld.Part1 = item.PrimaryPart
		weld.Parent = ra
		
		weld.Name = "VRWeld"

No part of the code you sent changes the position of the item (also name the weld before you parent it)

Yep that also made no difference
(obviously)

Your code should look something like this, along with the other stuff you need for the specific use case:

local hand = workspace.SomeHand
local item = workspace.SomeItem
local weld = Instance.new("WeldConstraint")

item:PivotTo(hand.CFrame)

weld.Part0 = hand
weld.Part1 = item

weld.Name = "SomeWeld"
weld.Parent = hand
1 Like

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