Rocket Launcher (Destroy All Rockets)

Hello, I’m having an issue with a rocket launcher I made. The way I scripted it involves events to remove the rocket once it collides with something, however currently it removes all rockets. This means if you fire multiple shots, when one of those shots hit, all the shots are instantly removed. Can I get some help with this? I will attach the model file to this for debugging, I have no idea where I have gone wrong on it as I’m quite new with tool designing.

RocketLauncher.rbxm (8.8 KB)

2 Likes

use spawn() on the function that creates rocket, and add a Touched function inside that function that destroys the rocket

ex:
function CreateRocket()
spawn(function()
rocket = Instance.new(“Part”)
rocket.Touched:Connect(function()
rocket:Destroy()
end
end)
end)

This will create the rocket in a single thread, and hopefully that will fix the issue

Hmm, thanks… I’ll give that a try and reply if it works.

I got that to work, but now it goes through all players and objects and doesn’t explode.

Show your code then, so we know the issue

is this possibly the start of your script?

if game:IsLoaded()==true then
break
end
end

local Tool=script.Parent.localPlayerMouse=A:Get() Icon= “rbxasset://textures\GunCursor.png”

Equipped:connect(function()

Yes, that is quite similar to the start of my script. Sorry for the long wait before this response, I have been inactive for a while doing other things relating to school.

What I wrote was actually wrong. Not only you shouldn’t use spawn(), it was in the wrong place.

Heres how the code should’ve actually looked like

function rocket()
–rocket stuff goes here
rocket.Touched:Connect(function()
local touchedevent = coroutine.create(function()
–explode rocket and delete it
coroutine.resume(touchedevent)
end

Ahh, thanks that worked out great!

its alright, the problem might be errors in the script, go on the thing that shows if there is any errors then get a professional scripter to help you if you really need it, i’m not a scripter so id find someone else.