Script makes all parts in group emit smoke on touch

the script below does this: if you touch one brick in a model group all bricks in that group become unanchored, i was wondering if it were possible that if it did the same but also: make every part emit smoke for a few seconds? so touch one brick in group, all bricks become unanchored all bricks emit smoke for a sec

function OnTouch(part)
	h = part.Parent:FindFirstChild("Humanoid")
	if h then
		for i,v in pairs(script.Parent.Parent:GetChildren()) do
			v.Anchored = false
		end
	end
end

script.Parent.Touched:Connect(OnTouch)

You can use Instance.new() to create a smoke object inside of the part.

Instance.new("Smoke")

I’m fairly sure this is possible. I think you’d just have to instance.new the smoke, and set the parent to the ā€˜v’ value…

and what then? im fairly bad at scripting

You would then parent the new Smoke object to the part in the ā€˜for i,v in pairs’ loop.
The code should look something like this.

local smoke = Instance.new("Smoke")
smoke.Parent = v

Instance.new() also has a second argument to automatically parent the new instance, but it causes lag and generally is not a good idea.

is that the complete code and where do i squeeze it in the script

That is not the complete code, sadly, but it’s a (really really basic) piece of code you can tamper with to fit your needs. It’s more to give you an idea of what you need to do.
The code would also fit into the ā€˜for i,v in pairs’ loop.

for i,v in pairs(script.Parent.Parent:GetChildren()) do
  v.Anchored = false
  local smoke = Instance.new("Smoke")
  smoke.Parent = v
end

and do i just add it to the back of the original post script or somewhere inbetween

You have to add it for your convenience

Wouldnt you place the variable before the for loop? So it can actually detect it?

local smoke = Instance.new("Smoke")
smoke.Parent = v 
for i, v in pairs(script.Parent.Parent:GetChildren()) do
v.Anchored = false
local function emitSmoke()
    for i, v in pairs(script.Parent.Parent:GetChildren()) do
        v.Ancored = false
        local smoke = Instance.new("Smoke")
        smoke.Parent = v
        smoke.Color = Color3.new(0, 0, 0)
        smoke.Opacity = 0.15
        smoke.RiseVelocity = 4
        smoke.Size = v / 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
1 Like

Not at all. That only creates one smoke instance, and I believe ā€˜v’ hasn’t been set as an actual variable yet.

Yeah, I am sorry, I just realized my mistake lol

This would be the answer to the question, yes. Good work, my friend!

1 Like

i put this in a seperate script but it didnt work

It has a typo in it.

v.Ancored = false

This should be v.Anchored = false.

with the corrected script it doesnt go unanchored anymore and doesnt emit smoke

Any errors in the output menu? I’d like a bit more information, simply ā€˜it’s not working’ is a bit confusing.

just checked and odly enough it doesnt say anything in the output, nothing gets added when i touch the part

Have you connected the .Touched event to the code? If so, put in a print statement in a few lines of the code, like the for loop and the beginning of the code block.