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

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

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

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)

1 comment

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.

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...

1 comment

0

Thank you for your input, but I already solved that problem by adding part.Parent = nil

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