Detecting if a part touches a players hand

Hello, I am trying to detect if a part is touching a players hand with the script being in the players hand instead of being in the part (parent of the script is the hand), However it is not detecting any objects when it touches a part. I tested the character model with the script in the workspace, and it works, but when I try it when a player is controlling it, it does not work. If you need any further details, I can gladly provide it. Any help is appreciated!

3 Likes

Could you please provide the problematic script?

2 Likes
local event = game:GetService("ReplicatedStorage"):WaitForChild('grabEvent')

rGripToggle = false
hasObject = false

event.OnServerEvent:Connect(function(p, rToggle, lToggle)
	if rToggle == true then
		print("rPressed sent")
		rGripToggle = true
	else
		rGripToggle = false
	end
end)

script.Parent.Touched:connect(function(hit)
	print("right hand has hit an object")
	if hit.CollisionGroup == "Grabbable" and hit.Anchored == false then
		print("its a grabbable object")
		if rGripToggle == true then
			print("collided and right hand is on")
			local attach = Instance.new("Attachment")
			attach.Parent = hit
			attach.Name = "onPart"
			attach.WorldPosition = script.Parent.band.WorldPosition
			
			local bsc = Instance.new("BallSocketConstraint")
			bsc.Parent = hit
			bsc.Name = "bscAttachment"
			bsc.Attachment0 = script.Parent.band
			bsc.Attachment1 = attach
			
			local ao = Instance.new("AlignOrientation")
			ao.Parent = hit
			ao.Attachment0 = script.Parent.band
			ao.Attachment1 = attach
			ao.Responsiveness = 200

			repeat
				wait()
			until rGripToggle == false
			
			attach:Destroy()
			bsc:Destroy()
			ao:Destroy()
		end
	end
end)
3 Likes

I tested your script parented to a default R15 character’s hand and it seemed to work. Does the part have the property CanTouch set to true?
image

1 Like

CanTouch is set to true, but the parts CanCollide is off for the hand.

2 Likes

CanCollide wouldn’t be a problem. Is the script creating a TouchInterest? This should be parented to the part like this:
image

3 Likes

The script is not creating a TouchInterest, and for some reason it is not showing the script in the hand either.

3 Likes

If the script isn’t there it could either be getting deleted or never being parented to begin with. What method are you using to put the script in the hand part?

2 Likes

Screenshot_2

2 Likes

I just tested this same setup and like you described all the scripts inside the StarterCharacter were deleted. It seems you simply can’t put scripts without them being deleted from the character. However, you can place the scripts in StarterCharacterScripts and they will get put in the character and then you can just tweak the script to use the hand.

2 Likes

Thank you, this solution worked!

2 Likes

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