I will give a few upvotes to whoever explains this to me.
function lightOnFire(part) print("Going to light this part on fire:") print(part.Name) fire = Instance.new("Fire") fire.Parent = part end firePart = game.Workspace.FirePart firePart.Touched:connect(lightOnFire) function putOutFire(part) print("Got to put out the fire on:") print(part.Name) fire = part:FindFirstChild("Fire") if fire then fire:Destroy() end end waterPart = game.Workspace.WaterPart waterPart.Touched:connect(putOutFire) firePart.Transparency = 1 waterPart.Transparency = 1
Hi...
function lightOnFire(part)--This script is creating a function to light something on fire print("Going to light this part on fire:") --this helps check is script is efficent in output print(part.Name)--same here fire = Instance.new("Fire")--Now we are going to make the fire fire.Parent = part --the parent of the fire is part we made the part varable with out function up here end firePart = game.Workspace.FirePart--There has to be something in workspace called FirePart firePart.Touched:connect(lightOnFire)--if this firePart was touched the function above will activate function putOutFire(part)--Now we r going to put out fire print("Got to put out the fire on:") --checking in output print(part.Name)--same here fire = part:FindFirstChild("Fire")--we r finding the parts child which is fire if fire then fire:Destroy()--we destroyed the fire end end waterPart = game.Workspace.WaterPart--You must have something in workspace called WaterPart waterPart.Touched:connect(putOutFire)--Now when touched we are activating the putOutFire function firePart.Transparency = 1--now both of these r invisible waterPart.Transparency = 1
Now idk if the script u got works but this is how it works
A function is a block of code that can be executed later. In the function lightOnFire
, part
is the argument (aka parameter) to the function -- a variable that you can change each time you call (use / execute) the function.
lightOnFire
prints two messages, then creates a new Fire object and adds it to part
.
lightOnFire lights a
part
on fire
firePart
is defined to be some part in the workspace called FirePart
. It's the first thing that's supposed to be on fire.
firePart is the source of fire
firePart.Touched
is an event. When an event happens, you can respond to that event by connecting to it. This line attaches the lightOnFire
function to this event -- whenever the event happens, lightOnFire
happens, and its argument part
will be whatever touched firePart
.
things that touch
firePart
will get lit on fire (lightOnFire
)
putOutFire
is almost the same. The only difference is that the objects that touch waterPart
might not already be on fire -- so you have to check if there is any fire before you try to remove it. (Really this check belongs in lightOnFireToo
so that you don't re-light the same object many times)