Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

instance.new not working when clicking with a tool?

so I tried scripting this script and put it inside a gun tool since my gun just needs some realistic feels (smoke appears when you shoot).

somehow when I shoot with my gun the smoke doesn't appear.

the script:

local Tool = script.Parent
 
Tool.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		Instance.new("Smoke", script.Parent.Handle)
		wait(2)
		script.Parent.Handle.Smoke:Destroy()
	end)
end)

I'm pretty new at scripting so I mostly got the script from a roblox wiki tutorial and just edited it.

it is a normal script and is inside the tool.

2 comments

0

Is it a local script? If so you would need to use a remote event due to most things on ROBLOX being FE or whatever it's called now.

0

well uhh I'm not sure how to use a remote event since I'm pretty new to scripting.

2 answers

✓ Accepted answer

Use Activated()

That all you need to change

local Tool = script.Parent

Tool.Activated:Connect(function()
    Instance.new("Smoke", script.Parent.Handle)
    wait(2)
    script.Parent.Handle.Smoke:Destroy()
end)

More about Tool

1 comment

0

thanks!

Try adding a position, smoke particles need a position for the emitter, and you didn't specify the position, so try doing this:

local Tool = script.Parent

Tool.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
        local smoke = Instance.new("Smoke", script.Parent.Handle)
	smoke.Position = script.Parent.Handle.Position
        wait(2)
        script.Parent.Handle.Smoke:Destroy()
    end)
end)

Hope I could help!

2 comments

0

should I use vector3 in this?

0

You should use Vector3 only if you want to make the smoke show up elsewhere, such as a fire. In this case, you don't need Vector3, because script.Parent.Handle, your gun, has a value called Position, which holds a Vector3 value, so no. The code I posted should explain.

This discussion is preserved as it was. New answers, comments, and votes are closed.