my scripts work fine but the part doesn’t obey physics
incase you still want the scripts here ya go
vr module script
local VRModule = {}
local DeviousService = require(script.Parent.DeviousService)
local playerServerStorage = game.Workspace.PlayerServerStorage
local CollectionService = game:GetService("CollectionService")
local function createHand(handName, character)
local hand = Instance.new("Part")
hand.Parent = playerServerStorage[character.Name]
hand.CFrame = character.HumanoidRootPart.CFrame
hand.Size = Vector3.new(0.4, 0.4, 0.4)
hand.Transparency = 0
hand.Color = Color3.fromRGB(0, 0, 255)
hand.Material = Enum.Material.ForceField
hand.CanCollide = false
hand.Anchored = true
hand.Name = handName
hand.Shape = Enum.PartType.Ball
local handHitbox = Instance.new("Part")
handHitbox.Parent = hand
handHitbox.Size = Vector3.new(0.75, 0.75, 0.75)
handHitbox.CanCollide = false
handHitbox.CFrame = hand.CFrame
handHitbox.Name = "Hitbox"
handHitbox.Transparency = 1
return hand, handHitbox
end
VRModule.setupPlayer = function(plr)
local playerFolder = Instance.new("Folder")
playerFolder.Name = plr.Name
playerFolder.Parent = playerServerStorage
local handL = createHand("leftHandServer", plr.Character)
local handR = createHand("rightHandServer", plr.Character)
return handL, handR
end
VRModule.updatePlayer = function(plr, LeftHandCFrame, RightHandCFrame, HeadCFrame, ItemHoldingL, ItemHoldingR)
-- UPDATE HANDS
local serverLeftHand = playerServerStorage[plr.Name].leftHandServer
local serverRightHand = playerServerStorage[plr.Name].rightHandServer
serverLeftHand.CFrame = LeftHandCFrame
serverRightHand.CFrame = RightHandCFrame
-- UPDATE PARTS BEING HELD
if ItemHoldingL ~= nil then
ItemHoldingL.Anchored = true
ItemHoldingL.CFrame = serverLeftHand.CFrame
end
if ItemHoldingR ~= nil then
ItemHoldingR.Anchored = true
ItemHoldingR.CFrame = serverRightHand.CFrame
end
end
VRModule.releaseItem = function(item, releaseCFrame)
if not item then return end
item.CFrame = releaseCFrame
local itemAncestors = DeviousService.getAncestors(item)
local itemGroup
for _, v in itemAncestors do
if CollectionService:HasTag(v, "FinalItemAncestor") then
itemGroup = v
end
end
if itemGroup == nil then
itemGroup = item
warn("unable to find item group for specified item " .. item:GetFullName())
end
if itemGroup:IsA("BasePart") then
itemGroup.Anchored = false
end
for _, v in itemGroup:GetDescendants() do
if not v:IsA("BasePart") then continue end
v.Anchored = false
end
end
return VRModule
vr hand local script
-- SERVICES
local VRModule = require(game.ReplicatedStorage.Modules.VRModule)
local VRService = game:GetService("VRService")
local StarterGUI = game:GetService("StarterGui")
local ContextActionService = game:GetService("ContextActionService")
local CollectionService = game:GetService("CollectionService")
local HapticService = game:GetService("HapticService")
-- CONSTANTS
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local camera = workspace.CurrentCamera
local serverHandL, serverHandR = VRModule.setupPlayer(player)
-- VARS
local itemHoldingL = nil
local itemHoldingR = nil
local headCFrame = nil
local grabbableObjects = {}
-- GET UNGRABBABLE TABLE (soon to be non-grabbable once i update scrip)
for _, inst in pairs(CollectionService:GetTagged("Item")) do
grabbableObjects[inst] = "FMIMP"
end
-- DEVIOUS STARTERGUI STUFF
StarterGUI:SetCore("VRLaserPointerMode", 1)
StarterGUI:SetCore("VREnableControllerModels", false)
-- CREATE HANDS FUNCTION
local function createHand(handName)
local hand = Instance.new("Part")
hand.Parent = character
hand.CFrame = character.HumanoidRootPart.CFrame
hand.Size = Vector3.new(0.4, 0.4, 0.4)
hand.Transparency = 0
hand.Color = Color3.fromRGB(0, 225, 255)
hand.Material = Enum.Material.ForceField
hand.CanCollide = false
hand.Anchored = true
hand.Name = handName
hand.Shape = Enum.PartType.Ball
local handHitbox = Instance.new("Part")
handHitbox.Parent = hand
handHitbox.Size = Vector3.new(0.75, 0.75, 0.75)
handHitbox.CanCollide = false
handHitbox.CFrame = hand.CFrame
handHitbox.Name = "Hitbox"
handHitbox.Transparency = 1
return hand, handHitbox
end
local leftHand, leftHandHitbox = createHand("leftHand")
local rightHand, rightHandHitbox = createHand("rightHand")
-- TODO_GRAB.ITEM.FUNCTION
function GrabItem(actionName, UserInputState, InputObject, Hand)
if InputObject.Position.Z >= 0.9 then
local partsInHand = workspace:GetPartsInPart(Hand:WaitForChild("Hitbox"))
local validParts = {}
local validPartsArrayAmmount = 1
for _, inst in ipairs(partsInHand) do
if grabbableObjects[inst] then
validParts[validPartsArrayAmmount] = inst
validPartsArrayAmmount += 1
end
end
if Hand == leftHand then itemHoldingL = validParts[1] end
if Hand == rightHand then itemHoldingR = validParts[1] end
elseif InputObject.Position.Z < 0.9 then
if Hand == leftHand then
VRModule.releaseItem(itemHoldingL, leftHand.CFrame)
itemHoldingL = nil
end
if Hand == rightHand then
VRModule.releaseItem(itemHoldingR, rightHand.CFrame)
itemHoldingR = nil
end
end
end
function GrabItemLeft(actionName, UserInputState, InputObject)
GrabItem(actionName, UserInputState, InputObject, leftHand)
end
function GrabItemRight(actionName, UserInputState, InputObject)
GrabItem(actionName, UserInputState, InputObject, rightHand)
end
-- TODO_PRIMARY.USE.FUNCTION
-- nil bc function in original script is bad
-- CONTEXT ACTION SERVICE HANDLER
local ActionsList = {
["GrabItemLeft"] = GrabItemLeft,
["GrabItemRight"] = GrabItemRight
}
local HandleAction = function(actionName, UserInputState, InputObject)
return ActionsList[actionName](actionName, UserInputState, InputObject)
end
ContextActionService:BindAction("GrabItemLeft", HandleAction, true, Enum.KeyCode.ButtonL1)
ContextActionService:BindAction("GrabItemRight", HandleAction, true, Enum.KeyCode.ButtonR1)
-- REMOVE SERVER HANDS CLONE
serverHandL.Transparency = 1
serverHandR.Transparency = 1
-- TODO_UPDATE.CLIENT.HANDS
function updateHead(move)
headCFrame = camera.CFrame * move
end
function updateLeftHand(move)
leftHand.CFrame = camera.CFrame * move
leftHand.Hitbox.CFrame = leftHand.CFrame
end
function updateRightHand(move)
rightHand.CFrame = camera.CFrame * move
rightHand.Hitbox.CFrame = rightHand.CFrame
end
VRService.UserCFrameChanged:Connect(function(part, move)
if part == Enum.UserCFrame.Head then
updateHead(move)
elseif part == Enum.UserCFrame.LeftHand then
updateLeftHand(move)
elseif part == Enum.UserCFrame.RightHand then
updateRightHand(move)
end
if itemHoldingL ~= nil then
itemHoldingL.CFrame = leftHand.CFrame
end
if itemHoldingR ~= nil then
itemHoldingR.CFrame = rightHand.CFrame
end
VRModule.updatePlayer(player, leftHand.CFrame, rightHand.CFrame, headCFrame, itemHoldingL, itemHoldingR)
end)
that final wacky thing called “DeviousService” (modulescript)
local DeviousService = {}
DeviousService.getAncestors = function(v)
local ancestors = {}
local ancestor = v.Parent
table.insert(ancestors,ancestor)
repeat
ancestor = ancestor.Parent
table.insert(ancestors,ancestor)
until ancestor.Parent == nil;
return ancestors
end
return DeviousService
oh god this formatting is gonna look awful
anyways i want them to be unanchored so i can throw them, i don’t care if the velocity just goes away ill deal with that later i just at least want them to fall for now