Touch Event not working correctly

So im trying to make a Touch Event whereas when you touch a player as the “Defected” it tranfers your title to them but this event only works once or not at all(had to join the game on roblox and try a few times to get results)

All Help Is Appreciated in advance

Script:

	local char = HotPotatoHolder.Character
	
	for i, v in pairs(char:GetChildren()) do
		if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("BasePart") then
			v.Touched:Connect(function(hit)
				if hit ~= nil and hit.Parent.Name ~= char.Name and Players:GetPlayerFromCharacter(hit.Parent) and canpass == true then
					canpass = false

					HotPotatoHolder = Players:GetPlayerFromCharacter(hit.Parent)

					HotPotato.Parent = hit.Parent
					Highlight.Parent = hit.Parent
					
					print("Passed Highlight and Hot Potato to "..hit.Parent.Name)
					task.wait(1)
					canpass = true
				else
					return
				end
			end)
		end
	end
	
2 Likes

Touch events are very unreliable. Sometimes firing, sometimes not. And also seems to not work if CanCollide property is false, even if CanQuery and CanTouch is true? its very strange.


workspace:GetPartsInPart()
or workspace:GetPartBoundsInBox()

might help you out

3 Likes

If you were to go down this route, you would need to add it into a loop. And I would also add OverlapParams to filter out all parts which are not needed.

2 Likes

Need more of the code, too much undefined. Where is the script located?

2 Likes

Server script in server script service

1 Like

Ill look more into it, but could you give an example on how it would be used instead of a Touched Function? How would i imply the loop or whatever is needed to keep it checking?

1 Like

From what i understand, you need to loop the hitbox and if a player touches the hitbox and the player with the hitbox has the potato, you give it to them, but I might just be completly wrong, I never used that command before.
Have a great day!:grinning:

2 Likes

You would need to check if the part that touches the hitbox is a children of a player’s model.

2 Likes

Should I make the hit box a players character lr should I make another part because I’m pretty sure the touch event uses whatever BoundsBox an object is in to detect if anything touches it

1 Like