I am currently working on a big project, and I have two problems: One is that a bullet can activate this, and two: is that it stays after you touch it. If there is a way to destroy the brick that this script is in, along with the script, I'd appreciate the help. :)
local part = script.Parent local EnemyGroup3 = game.Lighting.EnemyGroup3 local debounce = true part.Touched:connect(function() if debounce == true then debounce = false local Enemy = EnemyGroup3:Clone() wait(1) Enemy.Parent = Workspace wait(120) --waiting 3 seconds before setting debounce to true again debounce = true end end)
edit: And a way to make it so that only a player can activate this.
First, tab your code correctly. It makes it much easier to read.
We just check if the thing touching is part of a person. The easiest way to check is if the touching part's parent has a "Humanoid":
local part = script.Parent local EnemyGroup3 = game.Lighting.EnemyGroup3 local debounce = true part.Touched:connect(function(touchingPart) if debounce then if touchingPart.Parent and touchingPart.Parent:FindFirstChild("Humanoid") then debounce = false local Enemy = EnemyGroup3:Clone() wait(1) Enemy.Parent = Workspace wait(120) --waiting 2 minutes before re-enabling debounce = true end end end)
I am a bit confused as to what you mean by "it stays after you touch it."
Do you mean you want the button to vanish during those 120 seconds? I don't think that's the best way to communicate with players what is happening, since if they look for it they will not be able to find it during that period. Instead, just make it transparent or change color:
local part = script.Parent local EnemyGroup3 = game.Lighting.EnemyGroup3 local debounce = true part.Touched:connect(function(touchingPart) if debounce then if touchingPart.Parent and touchingPart.Parent:FindFirstChild("Humanoid") then part.Transparency = 0.5; -- Indicate that it is disabled debounce = false local Enemy = EnemyGroup3:Clone() wait(1) Enemy.Parent = Workspace wait(120) --waiting 2 minutes before re-enabling debounce = true part.Transparency = 0; -- Indicate that it is no longer disabled end end end)