Basically, I am trying to make a script that will activate a section of code whenever a specific part touches the part.
I am new to scripting so this is basically all I got.
if workspace.specificpart.Touched then workspace.doors:Destroy () end
Does anyone know how to help?
Well, Touched isn't a boolean, it's a script signal. You'll get false because Touched exists as a valid signal but it doesn't return anything, so the statement reads it as nil.
If you want to know what Touched does, it's called as a script signal of the
BasePart family (said family consists of Parts, NegativeParts, UnionOperations, etc.). When Touched fires, it passes the
BasePart that made contact with the
BasePart whose Touched event is listening. For example, if a player's character is R6 and their left leg hits the part listening for Touched, the passed
BasePart will be
In order to associate any signal with any function (pre-written or post-written),
Connect() is necessary. If no function was previously written for use with the signal, you can define this function within the signal:
BasePart.Touched:Connect(function(hit) -- some code end)
Or, you can associate an existing function with it:
function foo() -- code end BasePart.Touched:Connect(foo) -- Using foo() with make Lua assume you're running the function. You do not want to use parenthesis if you're linking an existing function.
For the main issue at hand, every Instance has a property called
Name, which is a string that represents the name given to the Instance. This property can be changed by the scripter at will; it's essentially a dynamic property. The rest is up to you.
You can use the "hit" paramter of the .Touched event :
workspace.part.Touched:Connect(function(hit) if hit.Name = specifiPart.Name then workspace.doors:Destroy() end end)
Here if a part nammed lake the specificPartso if the specificPart tocuhes) the current part, we do actions