Issue with .Touched event detection

I am trying to find the position of the yellow balls collision but half of the time i doesnt detect collision outside of the player character or it only detects the collision from the zombie. I am not sure what may be causing the problem

the position of the collision is indicated by this white star:

image

for _, Point in pairs(Points) do

	local Part = Instance.new("Part")
	Part.Anchored = true
	Part.CanCollide = false
	Part.Size = Vector3.new(2,2,2)
	Part.Color = Color3.fromRGB(255, 170, 0)
	Part.Shape = Enum.PartType.Ball

	Part.CFrame = CFrame.new( 
		Point
	)

	Part.Parent = workspace.SuperBallPoints
				
	Part.Touched:Connect(function(hit)
					
	if hit:IsA("Part") and not hit:IsDescendantOf(character) then
						
		if hit.CanCollide == true and SparkHit == nil then
							
			SparkHit = Part
							
			workspace.SparkEffect.SparkPart.CFrame = Part.CFrame
							
			Part.TouchEnded:Connect(function(hitEnd)
				if hitEnd == hit then
					SparkHit = nil
				end
			end)
		end
	end
	end)
end

Documentation explains the issue with .Touched and between anchored to anchored parts ( needs physics interaction to work, anchored to unanchored is fine).

Try using other forms of collision detection, shapecasting, spatial queries, or raycasting instead.

thank you this helped me a lot!

2 Likes

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