Hit detection failing

So basically, I’m trying to detect if the player is still touching a part or not, but I’m having some problems with it. When someone stands inside the part and jumps, the bool value disappears, even if they are still in the part. (The part has no collision and is higher than the character). How can I fix these issues, or is there another method for hit detection? Script below.

script.Parent.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		if hum:FindFirstChild("Capturing") then
			
		else
			local capturing = Instance.new("BoolValue")
			capturing.Name = "Capturing"
			capturing.Parent = hum
		end
	end
end)

script.Parent.TouchEnded:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		if hum:FindFirstChild("Capturing") then
			hum.Capturing:Destroy()
		end
	end
end)
1 Like

TouchEnded is a weird event, it doesn’t work properly at times and can be activated if someone jumps in the part, even though they were still touching it throughout the whole jump. I suggest using Part:GetTouchingParts() every second or so to detect if there is a player’s character in that part

2 Likes

GetTouchingParts will also make it more straightforwards to correctly handle multiple people capturing at once if you want to do something like have team based capturing rather than just individual players.

For example, you might want to have the capture stop when an enemy is also near the part, but then start again if they walk away, even though you did not touch or stop touching the part when they walked away.

3 Likes