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
4 years ago
Edited 4 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:

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

2 answers

Log in to vote
0
Answered by
OnaKat 444 Moderation Voter
4 years ago
Edited 4 years 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)

More about Tool

0
thanks! Rdumb1 4 — 4y
Ad
Log in to vote
0
Answered by
A_thruZ 29
4 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:

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 — 4y
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 — 4y

Answer this question