Hello! So I’m trying to have a sword follow a VR hand’s CFrame to make it seem like the player is holding the sword. But It’s not quite working. Sorry if this isn’t enough information. It’s kinda hard to explain. But here is my code. hopefully my code will help you understand what I mean.
So I have two scrips. One that creates the hands and one that makes the sword follow the hand.
Script that makes the hands:
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local camera = game.Workspace.CurrentCamera
local starterGui = game:GetService("StarterGui")
camera.CameraType = "Scriptable"
camera.HeadScale = 1
character.HumanoidRootPart.Anchored = true
workspace.CurrentCamera.CFrame = CFrame.new(workspace.CurrentCamera.CFrame.Position)
starterGui:SetCore("VRLaserPointerMode", 0)
starterGui:SetCore("VREnableControllerModels", false)
local function createHand(handType)
local hand = Instance.new("Part")
hand.Parent = character
hand.CFrame = character.HumanoidRootPart.CFrame
hand.Size = Vector3.new(0.4, 0.4, 1)
hand.Transparency = 0
hand.Color = Color3.new(1, 0.72, 0.6)
hand.Material = Enum.Material.SmoothPlastic
hand.CanCollide = false
hand.Anchored = true
hand.Name = handType
return hand
end
local leftHand = createHand("rightHand")
local rightHand = createHand("leftHand")
local inputService = game:GetService("UserInputService")
inputService.UserCFrameChanged:Connect(function(part, move)
-- Code will go here
if part == Enum.UserCFrame.LeftHand then
leftHand.CFrame = camera.CFrame * move
elseif part == Enum.UserCFrame.RightHand then
rightHand.CFrame = camera.CFrame * move
end
end)
Script that makes the sword follow the hand:
wait(1)
local Saber = script.Parent
local Character = game.Players.LocalPlayer.Character
local Hand
if Saber.Name == "BlueSaber" then
Hand = Character.righthand
elseif Saber.Name == "RedSaber" then
Hand = Character.lefthand
end
while true do
Saber:PivotTo(Hand.CFrame)
game:GetService("RunService").Heartbeat:Wait()
end
Sorry if this is confusing. And thanks for the help!