Script makes all parts in group emit smoke on touch

wait so, i completely replaced the original code with this one, not added it to it

Ah, easy fix then! You need to add back the event you made before.

script.Parent.Touched:Connect(OnTouch)

This is what actually makes the function activate.
Remember to change the name of the function youā€™re activating! As of right now, ā€˜OnTouchā€™ doesnā€™t exist. Youā€™d want it to be ā€˜emitSmokeā€™ in this particular instance.

1 Like

so this goes at the start of the whole code?

Correct! The code block, or the function, goes at the beginning of the script. The events go at the end, such as the ā€˜Touched:Connectā€™ event.

i added it at the top and OnTouch gets an orange line under it

As I stated before, you would add that on the bottom, and you need to change ā€˜OnTouchā€™ to ā€˜emitSmokeā€™. ā€˜OnTouchā€™ does not actually exist, as you havenā€™t defined it as a function.

but earlier you said correct when i asked if it goes to the start of the script?.. now im confused

When I said ā€˜correctā€™, I thought you were referring to the ā€˜emitSmokeā€™ function. My bad. I didnā€™t know you were talking about the event.

As for the code, it would beā€¦

-- function here, please don't just copy and paste this into the code. this isn't actual code. this is an example.

script.Parent.Touched:Connect(emitSmoke)

okay then so whats the complete script because im afraid to try stuff now, lol

Donā€™t be afraid, my friend, I didnā€™t mean to spook you! Itā€™s like learning to ride a bike. After youā€™ve done it a few times, itā€™s easy!
Weā€™re here for you on the devforum, feel free to ask questions. Learning is easier when you have people to help you.

alright this all worked except:
1: all the other parts in the group unanchored and got smoke but the part i touched didnt

Thatā€™s odd. I canā€™t help you much, though, unless you provide more detail. Try putting a print statement inside of the ā€˜forā€™ loop?

this was put in the output as red: 21:35:44.069 - Workspace.Regen Parts.Model.Part.Unanchor:9: attempt to perform arithmetic (div) on Instance and number

Ah! I see the issue. Thatā€™s a bit of flavour that the original writer of the script put in; itā€™s purely for aesthetics. You can remove it, and it wonā€™t cause any issues.

You can remove the

smoke.Size = v / 4

part.

1 Like

it all worked! thanks! just putting the script here so i can mark the solution box (since some edits were done to the op script i cant solution that)

local function emitSmoke()
for i, v in pairs(script.Parent.Parent:GetChildren()) do
v.Anchored = false
local smoke = Instance.new(ā€œSmokeā€)
smoke.Parent = v
smoke.Color = Color3.new(0, 0, 0)
smoke.Opacity = 0.15
smoke.RiseVelocity = 4
end

wait(5) -- Amount of till making smoke dissapear

for i, v in pairs(script.Parent.Parent:GetChildren()) do
	v.Smoke:Destroy()
end

end
script.Parent.Touched:Connect(emitSmoke)

Youā€™re very welcome, my friend! I hope this helps your game out, or just with general scripting knowledge.

1 Like

Yes! It indeed helped my game out a lot! Idk if this counts as self advertise or something but the game is called size changer feel free to check it out :slight_smile: (made by kiri1234jojo if it helps to find it)

Well, Iā€™m glad it worked out. Have a good rest of your week everyone, and stay safe!

2 Likes