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

How do I make something disapear when someone touches it?

Asked by 10 years ago

I used to know this, but its been a long time since ive programmed, so is it like

function onTouch()
game.Worksapce.Parent:Destroy()

I really wanna know

2 answers

Log in to vote
0
Answered by 10 years ago

Good try attempting to script it yourself. Indeed, both lines are correct, but you forgot quite a lot.

script.Parent.Touched:connect(function(player) --So, the brick is touched and the person touching it is now called "player"
    Humanoid = player.Parent:FindFirstChild("Humanoid") --Searches for a humanoid
    if Humanoid ~= nil then --If the humanoid is present (Basically checks for a player) then...
        script.Parent:Destroy() --Completely removes the object from the game
    end --Ends the if statement
end --Ends the function
--Put this in the object that gets destroyed. Otherwise, this may not work properly
Ad
Log in to vote
0
Answered by 10 years ago

I don't know if this is what you are wanting, but this may work for you.

-- You must put this in a part
function onTouched(hit)
    if hit.Name == "Part" then --Change this to what ever the part is called fyi :P
    hit:remove() 
end
end

script.Parent.Touched:connect(onTouched)

You have to put this script in a part.

Example When you step on the part i will call "P1" It will destroy a different part i will call "P2" So, the the script should be in "P1" The script should look like:

-- You must put this in a part
function onTouched(hit)
    if hit.Name == "P2" then --Change this to what ever the part is called fyi :P
    hit:remove() 
end
end

script.Parent.Touched:connect(onTouched)

Answer this question