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.
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: