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)
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