Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make this destroy itself, and only works if a player touches it?

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.

1 answer

✓ Accepted answer

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)

2 comments

0

Actually, it's a enemy spawn-field. It's transparent to begin with. What I'm asking is if it's possible to make the brick destroy itself.

0

Why?

This discussion is preserved as it was. New answers, comments, and votes are closed.