Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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)
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. TheRings0fSaturn 28 — 10y
0
Why? BlueTaslem 18071 — 10y
Ad

Answer this question