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

How do I allow a certain brick to pass through a wall?

Asked by 10 years ago

I'm trying to make a certain brick to pass through a wall. I want to let a certain brick called "x" to pass through the wall "y". If the wall detects another brick, whose name is not "x", then it will delete it.

function lala()
    if 
        game.Workspace.Name.x -- I have no idea what to do around here
        then
        print("x confirmed")
    else
        local part = game.Workspace.Part -- This one too
        part:Destroy()
        print("Removing this junk.")
    end
end
script.Parent.Parent.y.Touched:connect(lala)

Now, the problem is that the wall will immediately execute the Else code, whenever the "x" block passes through. It will delete ANY random brick that has the name "Part".

So my questions are:

  • How do I let "x" pass through the wall "y", without the else code will be executed?
  • How do I let the wall "y" delete the brick that passes through?

2 answers

Log in to vote
0
Answered by 10 years ago

Your conditional statements are incorrectly formatted.

To check a name and compare it to your criteria, an equation is in order.

if part.Name == x then

end

In this case, part is not defined. Luckily, however, you can extract this information through your touched event.

x = "Passable Part" -- Or part hierarchy (game.Workspace["Passable Part"])
y = game.Workspace.Door -- Or a script hierarchy (script.Parent)

function touched(part)
    if part.Name == x or part == x then
        print("Part passed! I suggest toggling the door's CanCollide for effect.")
    else
        print("Part is not x.")
    end
end

y.Touched:connect(touched)
0
Aah, most excellent. After editing your script a bit, it worked. It didn't not solved my second problem though, but I fixed it by implementing (part.Parent = nil) below the Else, in case someone else had this similar problem too. Bussemand 0 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Do what Drako did, then maybe instead of printing a message in output, try first renaming the part to "deleteme". Then add game.Workspace.deleteme:Destroy()

Just a guess...

0
Thank you for your input, but I already solved that problem by adding part.Parent = nil Bussemand 0 — 10y

Answer this question