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

Why wont this brick remover work the way I want it to?

Asked by
EpicLilC 150
8 years ago

So I created a part remover like this..

function removebricks()
    workspace.Part:Remove()
end
game.Workspace.PartDeleter.Touched:connect(removebricks)

and it works, but when I touch PartDeleter, it just removes any thing named part in the game. How would I make it so that if the part named PartDeleter was touched by a ton of parts, it would remove all of them?

1 answer

Log in to vote
2
Answered by
funyun 958 Moderation Voter
8 years ago
--First thing's first: functions can have arguments. Think of
--mathematical functions.

function f(x)
    print(2 * x + 5)
end

f(1)
f(2)
f(3)

--So, you call the function with an argument; an x-value in this case.
--Strings can also be arguments.

function echo(message)
    print(message)
end

echo("hey")
echo("hi")
echo("what's up")

--Now, event listeners (functions you declare that you connect to
--events) can also have arguments. If you visit this link:

this one

--You see that it has the name of the event, Touched, and what it would
--pass as an argument to it's connected function. Different events
--pass different arguments. In particular, the Touched event passes the part that
--touched as an argument to the connected function. Knowing that, let's make a function to
--destroy whatever touches your part.

function removebricks(PartThatTouched)
    --remove() is a deprecated function, meaning Roblox made a better version of it. Just use Destroy().
    PartThatTouched:Destroy()
end

game.Workspace.PartDeleter.Touched:connect(removebricks)
Ad

Answer this question