1 | function OnTouch() |
2 | Instance.new( "Smoke" ,script.Parent:FindFirstChild( "Part" )) |
3 | end |
4 | script.Parent.Touched:connect(OnTouch) |
I'm trying to insert smoke into any part that comes into contact with the part. Do I possibly need an if~ nil type statement?
I'm new to scripting still, but I'll answer to best of my abilities. Ok, so what's wrong is here, is you never checked for a part that would touch it. Here's how I would do it
01 | local part = script.Parent -- Define the part |
02 |
03 | function OnTouch(ThingThatTouchedTheBrick) --The thing in brackets is a parameter. I'm still a bit new to scripting, so I'm not great at explaining. But basically, a parameter is a variable in the defintion of a function. |
04 |
05 | local part = ThingThatTouchedTheBrick --make a variable for the parameter(Not sure if it's necessary, but we'll do it anyway) |
06 |
07 | if part then --if a part touched it, then we continue |
08 | local smoke = Instance.new( "Smoke" ,part) -- creates smoke in the part that touched it |
09 | end |
10 | end |
11 |
12 | part.Touched:connect(OnTouch) --connect the event with the function |
I hope this helped, and if it did, please accept my answer! :D If you have any questions, feel free to ask me in the comments!