Having trouble with finding part on grab script

local module

local module = {}

-- //Services
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- //Folder
local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents")

-- //Remotes
local UnreliableWeld = RemoteEvents:FindFirstChild("UnreliableWeld")

function module:input(player, character)
	
	-- //BaseParts
	local RightDigit = character:FindFirstChild("Right Digit")
	local LeftDigit = character:FindFirstChild("Left Digit")
	
	-- //Humanoid
	local Humanoid = character:FindFirstChild("Humanoid")
	local Animator = Humanoid:FindFirstChild("Animator")
	
	local RightAnimation = Animator:LoadAnimation(script:FindFirstChild("RightAnimation"))
	local LeftAnimation = Animator:LoadAnimation(script:FindFirstChild("LeftAnimation"))
	
	RightAnimation:Play()
	LeftAnimation:Play()
	
	-- //Debounce
	local RDebounce = false
	local LDebounce = false
	
	-- //Variables
	local RPart
	local LPart
	
	UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean) 
		if input.KeyCode == Enum.KeyCode.ButtonR1 or input.KeyCode == Enum.KeyCode.ButtonR2 then
			if not RDebounce then
				RDebounce = true
				RPart = RightDigit:GetTouchingParts()
				print(#RPart, RPart)
				UnreliableWeld:FireServer(RDebounce, RPart)
			end
		elseif input.KeyCode == Enum.KeyCode.ButtonL1 or input.KeyCode == Enum.KeyCode.ButtonL2 then
			if not LDebounce then
				LDebounce = true
				LPart = LeftDigit:GetTouchingParts()
				UnreliableWeld:FireServer(LDebounce, LPart)
			end
		end
	end)
	
	UserInputService.InputEnded:Connect(function(input: InputObject, gameProcessedEvent: boolean) 
		if input.KeyCode == Enum.KeyCode.ButtonR1 or input.KeyCode == Enum.KeyCode.ButtonR2 then
			if RDebounce then
				RDebounce = false
				UnreliableWeld:FireServer(RDebounce, RPart)
			end
		elseif input.KeyCode == Enum.KeyCode.ButtonL1 or input.KeyCode == Enum.KeyCode.ButtonL2 then
			if LDebounce then
				LDebounce = false
				UnreliableWeld:FireServer(LDebounce, LPart)
			end
		end
	end)
	
end


return module

server module

local module = {}

-- //Services
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- //Folder
local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents")

-- //Remotes
local UnreliableWeld = RemoteEvents:FindFirstChild("UnreliableWeld")

-- // 
local partBound = {
	["Right Digit"] = nil,
	["Left Digit"] = nil
}

UnreliableWeld.OnServerEvent:Connect(function(player: Player, RDebounce, RPartTable, LDebounce, LPartTable) 

	-- //Character
	local character = player.Character

	-- //Digits
	local RightDigit = character:FindFirstChild("RightDigit")
	local LeftDigit = character:FindFirstChild("Left Digit")

	if partBound["Right Digit"] ~= nil and RDebounce then
		return
	end

	if partBound["Left Digit"] ~= nil and LDebounce then
		return
	end


	for _, R in pairs(RPartTable) do
		if RDebounce then
			if partBound["Right Digit"] == nil then
				if R then
					partBound["Right Digit"] = R.Name

					-- //Weld
					local Weld = Instance.new("WeldConstraint", RightDigit)
					Weld.Part0 = RightDigit
					Weld.Part1 = R

					if R.Name == "Right Arm" then
						-- //LineForce
						if not RightDigit:FindFirstChildWhichIsA("LineForce") then
							local LineForce = Instance.new("LineForce", RightDigit)
							LineForce.Attachment0 = R:FindFirstChild("RightGripAttachment")
							LineForce.Attachment1 = RightDigit:FindFirstChildWhichIsA("Attachment")
							LineForce.ReactionForceEnabled = true
						end
					end

				end

			end
		elseif not RDebounce then
			partBound["Right Digit"] = nil

			if RightDigit:FindFirstChild("LineForce") then
				-- //LineForce 
				local LineForce = RightDigit:FindFirstChild("LineForce")
				LineForce.Parent = nil
			end

			if RightDigit:FindFirstChildWhichIsA("WeldConstraint") then
				local Weld = RightDigit:FindFirstChild("WeldConstraint")
				Weld:Destroy()
			end

			if table.find(partBound["Right Digit"], R.Name) then
				table.remove(R)
			end
		end
	end

end)

return module

seems to not be touching other parts when it is.

What do RightDigit and LeftDigit look like? Is this a VR setup or something more like Gang Beasts?

GetTouchingParts is meant for intersection, so if the parts are only loosely touching it might not be reliable.

GetTouchingParts also doesn’t work for non-collide parts unless the part has a TouchInterest added to it.

Here are what the docs say about GetTouchingParts for more details:

Returns a table of all parts that are physically interacting with this part. If the part itself has CanCollide set to false, then this function returns an empty table unless the part has a TouchInterest object parented to it (meaning something is connected to its Touched event). Parts that are adjacent but not intersecting are not considered touching. This function predates the WorldRoot:GetPartsInPart() function, which provides more flexibility and avoids the special TouchInterest rules described above. Use WorldRoot:GetPartsInPart() instead.

the digits are just an alternative for fingers meshpart for a vr game, i have everything working but the grab is being a pain - gettouchingparts is deprecated for meshparts but idek

yeah imma use worldroot instead as i have to also use the touched event which is a pain.

1 Like

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