Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

instance.new not working when clicking with a tool?

Asked by
Rdumb1 4
5 years ago
Edited 5 years 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:

1local Tool = script.Parent
2 
3Tool.Equipped:Connect(function(Mouse)
4    Mouse.Button1Down:Connect(function()
5        Instance.new("Smoke", script.Parent.Handle)
6        wait(2)
7        script.Parent.Handle.Smoke:Destroy()
8    end)
9end)

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

2 answers

Log in to vote
0
Answered by
OnaKat 444 Moderation Voter
5 years ago
Edited 5 years ago

Use Activated()

That all you need to change

1local Tool = script.Parent
2 
3Tool.Activated:Connect(function()
4    Instance.new("Smoke", script.Parent.Handle)
5    wait(2)
6    script.Parent.Handle.Smoke:Destroy()
7end)

More about Tool

0
thanks! Rdumb1 4 — 5y
Ad
Log in to vote
0
Answered by
A_thruZ 29
5 years ago

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

01local Tool = script.Parent
02 
03Tool.Equipped:Connect(function(Mouse)
04    Mouse.Button1Down:Connect(function()
05        local smoke = Instance.new("Smoke", script.Parent.Handle)
06    smoke.Position = script.Parent.Handle.Position
07        wait(2)
08        script.Parent.Handle.Smoke:Destroy()
09    end)
10end)

Hope I could help!

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

Answer this question