Still have questions? Join our Discord server and get real time help.
0

# instance.new not working when clicking with a tool?

Edited 1 year ago

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.

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. k1nq 30 — 1y
0
well uhh I'm not sure how to use a remote event since I'm pretty new to scripting. Rdumb1 4 — 1y

0
OnaKat 444
1 year ago
Edited 1 year ago

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)



0
thanks! Rdumb1 4 — 1y
0
A_thruZ 29
1 year ago

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!

0
should I use vector3 in this? Rdumb1 4 — 1y
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. A_thruZ 29 — 1y