I’m making a VR game with tools, and I can’t figure out how to make it so that you can grab them with your hand.
I took the hand script from a dev-forum post, but here's the script;
VRService = game:GetService('VRService')
UIS = game:GetService('UserInputService')
if not VRService.VREnabled then return end
StarterGui:SetCore("TopbarEnabled", false)
StarterGui:SetCore("VRLaserPointerMode", 0)
StarterGui:SetCore("VREnableControllerModels", false)
local Left = script:WaitForChild('L')
Left.Parent = workspace.Camera
local Right = script:WaitForChild('R')
Right.Parent = workspace.Camera
HeadScale = 2
Cam = workspace.CurrentCamera
Cam.HeadScale = HeadScale
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CFrame = CFrame.new(0,6.5,-1.2)
game:GetService('RunService').RenderStepped:Connect(function()
local LC = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
local RC = VRService:GetUserCFrame(Enum.UserCFrame.RightHand)
Left.CFrame = (Cam.CFrame*CFrame.new(LC.p*2))*CFrame.fromEulerAnglesXYZ(LC:ToEulerAnglesXYZ())
Right.CFrame = (Cam.CFrame*CFrame.new(RC.p*2))*CFrame.fromEulerAnglesXYZ(RC:ToEulerAnglesXYZ())
end)
Left.Touched:Connect(function(hit)
if hit.Parent:isA(Instance.new("Tool")) then
UIS.InputBegan:Connect(function(input, processed)
if input.UserInputType == Enum.KeyCode.ButtonL2 then
local tool = hit.Parent
tool.CFrame = Left.CFrame
end
end)
end
end)
Right.Touched:Connect(function(hit)
if hit.Parent:isA(Instance.new("Tool")) then
UIS.InputBegan:Connect(function(input, processed)
if input.UserInputType == Enum.KeyCode.ButtonR2 then
local tool = hit.Parent
tool.CFrame = Right.CFrame
end
end)
end
end)
Here’s the part where I tried to make the hand grab the tools;
while wait() do
Left.Touched:Connect(function(hit)
if hit.Parent:isA(Instance.new("Tool")) then
UIS.InputBegan:Connect(function(input, processed)
if input.UserInputType == Enum.KeyCode.ButtonL2 then
local tool = hit.Parent
tool.CFrame = Left.CFrame
end
end)
end
end)
Right.Touched:Connect(function(hit)
if hit.Parent:isA(Instance.new("Tool")) then
UIS.InputBegan:Connect(function(input, processed)
if input.UserInputType == Enum.KeyCode.ButtonR2 then
local tool = hit.Parent
tool.CFrame = Right.CFrame
end
end)
end
end)
end
It doesn’t even detect the tool being grabbed.
I tried to make it print that it hit something, but nothing ever showed up.