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

Smoke not inserting in function?

Asked by 8 years ago
function OnTouch()
Instance.new("Smoke",script.Parent:FindFirstChild("Part"))
end
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?

1 answer

Log in to vote
1
Answered by
Peeshavee 226 Moderation Voter
8 years ago

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

local part = script.Parent -- Define the part

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.

local part = ThingThatTouchedTheBrick --make a variable for the parameter(Not sure if it's necessary, but we'll do it anyway)

if part then --if a part touched it, then we continue
local smoke = Instance.new("Smoke",part) -- creates smoke in the part that touched it
    end
end

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!

0
Thanks! MEANDUDE87 60 — 8y
Ad

Answer this question