Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

instance.new not working when clicking with a tool?

Asked by
Rdumb1 -11
14 days ago
Edited 14 days 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 — 14d
0
well uhh I'm not sure how to use a remote event since I'm pretty new to scripting. Rdumb1 -11 — 14d

2 answers

Log in to vote
0
Answered by
OnaKat 168
14 days ago
Edited 14 days 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 -11 — 14d
Ad
Log in to vote
0
Answered by 14 days 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 -11 — 14d
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. flunkywhat 20 — 14d

Answer this question