Making a rocket launcher work

I have alot of scripts here and I dont think they go in code review.

I want these scripts to make a rocket in rs close to the workspace and go to the mouses position and if it comes in contact with anything except the player or the tool.

Server script in tool:

local tool = script.Parent

local fireEvent = tool:WaitForChild("Fire")

fireEvent.OnServerEvent:Connect(function(plr, mouseHit, coolDown)

game.ReplicatedStorage.Fire:FireAllClients(plr, mouseHit,tool)

end)

Local script in tool:

local tool = script.Parent
local fireEvent = tool:WaitForChild("Fire")

coolDown = 3
canFire = true

tool.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		if canFire then
			fireEvent:FireServer(mouse.Hit.Position, coolDown)
			canFire = false
			wait(coolDown)
			canFire = true
		end
	end)
end)

Server script in server script service:

local debris = game:GetService("Debris")

game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(plr, rocketPos, mouseHit)
	local explosionPart = Instance.new("Part", workspace)
	explosionPart.Anchored = true
	explosionPart.CanCollide = false
	explosionPart.Transparency = 1
	explosionPart.Position = rocketPos



	local explosion = Instance.new("Explosion", workspace)
	explosion.Position = explosionPart.Position
	debris:AddItem(explosionPart, 3)
end)

Local script in starterplayer:

local debris = game:GetService("Debris")

game.ReplicatedStorage.Fire.OnClientEvent:Connect(function(plr, mouseHit, tool)
	local rocket = game.ReplicatedStorage.Rocket:Clone()
	rocket.Parent = workspace
	rocket.CFrame = CFrame.new(tool.EnhancedCone.Position, mouseHit)

	local bv = Instance.new("BodyVelocity", rocket)
	bv.Velocity = CFrame.new(rocket.Position, mouseHit).LookVector * 100

	rocket.Touched:Connect(function(hit)
		if hit:IsA("BasePart") then
			if hit.Parent ~= tool then
				rocket:Destroy()
				game.ReplicatedStorage.Fire:FireServer(rocket.Position, mouseHit)
			end
		end
		debris:AddItem(rocket, 3)
	end)
end)

What its doing is, its detonating when they click instantly.

Please help!

1 Like

Oh and if this is ment for code review, please tell me.

in this script it will actually detonate fast because u didnt put a wait or an Touch Event like try this:

local debris = game:GetService("Debris")

game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(plr, rocketPos, mouseHit)
	local explosionPart = Instance.new("Part", workspace)
	explosionPart.Anchored = true
	explosionPart.CanCollide = false
	explosionPart.Transparency = 1
	explosionPart.Position = rocketPos

          explosionPart.Touch:Connect(function()
                   	local explosion = Instance.new("Explosion", workspace)
	                explosion.Position = explosionPart.Position
	                debris:AddItem(explosionPart, 3)
              end

end)

Still does the exact same thing.

try adding a wait(1) up the explosionPart.Touch because i think it might be touching your character and its triggering

No, now it just waits 1 second then blows me up.

I don’t think it is actually creating the rocket and just generates the explosion.

Now it is generating like 7 explosion parts aswell.

i think its because u are already destroying the rocket before firing the event with rocket.Position

Ok I moved them but same outcome.

try reverse it like this:

rocket.Touched:Connect(function(hit)
		if hit:IsA("BasePart") then
			if hit.Parent ~= tool then
			
				game.ReplicatedStorage.Fire:FireServer(rocket.Position, mouseHit)
               rocket:Destroy()
			end
		end
		debris:AddItem(rocket, 3)
	end)
end)

oh nvm u already done it

I am using welds to weld the model, could that be a factor?

Also the rocket isnt anchored and cancollide is true.

which model actually are you welding? the rocket projectile?

I welded the parts of the rocket launcher together, I cant anchor them because its a tool.

No not the rocket, I welded the whole rocket launcher together.

oh thats not a factor but is the model canCollide = false if not then it could be a factor that the explosion explode

The model is CanCollide = true.

yea i think thats the factor that is affecting the rocket projectiles

So I make it CanCollide = false?