How to detect when a part touches this part?

Im trying to make a script where a landmine detects when a player and a bullet touches it, but it is not detected when ANY part touches it?

db = true
script.Parent.Touched:Connect(function(obj)
	print("asdd")
	if obj.Name == "bullet" then
		print("absd")
	end
	
	local humanoid = obj.Parent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		if db == false then return end
		if humanoid.Parent.Name == script.Parent.PlayerName.Value then return end
		db  = false
		humanoid.Health = 0
		script.Parent.Explosion:Play()
		script.Parent.ParticleEmitter.Enabled = true
		wait(0.4)
		script.Parent.ParticleEmitter.Enabled = false
		wait(2)
		script.Parent:Destroy()
	end
end)


Your debounce (db) should be set to true after the end of your waits, just before script.Parent.Destroy().

You should be using task.wait() instead of wait().

Fast moving parts like bullets can miss firing the Touched event if they are rendered between frames (skipping past the target). You can try making the bullet or landmine larger for testing to see if “asdd” prints.

Right after the local humanoid line put

print("humanoid.Name = ", humanoid.Name, "  PlayerName.Value = ", script.Parent.PlayerName.Value)

to see what is being touched. That way you can see why or why not the later if checks are being passed.

1 Like

Thankyou for the fix for the rest of the script, but the main feature I want to add still does not work,

I do not think it is the size of the object that is the problem, I have added a script to this part that touches the landmine and prints nothing when it touches it, but prints “add” whenever it touches the player.

I think it is something to do with the Touched:Connect(function(obj) part of the script

Here is the script for the part that touches the landmine just in case:

script.Parent.Touched:Connect(function()
	print("add")
end)

Here is a video showing you the problem:

bump


i think parts without physics (anchored parts) cant touch anything

you have to check for touching parts inside of a loop with
workspace:GetPartsInPart(part, overlapParams)

Well the “add” keeps printing in the Part, so is it the mine that’s the issue?

(@happya_x Anchored Parts can still fire a Touched event.)

Is your mine CanTouch property false? That way it won’t register any touches

Your other script seems to be erroring on line 9 checking for the humanoid every time. Did you use the print suggestion I gave in my previous post?

Cantouch is active, and I did ujse the suggestion in your previous post, and it is not anchord anyways

The piece on the floor is unanchored and CanTouch true? I thought that was the mine.

nevermind it is because it is not ancored and it takes time for it to update because roblox is slow