How should I go about making my own rocket launcher?

I’ve been trying to replicate the Classic Rocket Launcher tool but I’m having a hard time doing so. I keep getting this error and for some reason, the rocket teleports under the tool and explodes…

  10:19:01.412  Workspace.Rocket Launcher.Rocket:12: invalid argument #2 to 'new' (Vector3 expected, got CFrame)  -  Server - Rocket:12
  10:19:01.413  Stack Begin  -  Studio
  10:19:01.413  Script 'Workspace.Rocket Launcher.Rocket', Line 12  -  Studio - Rocket:12
  10:19:01.413  Stack End  -  Studio

This is the local script that sends the position of the mouse when it is clicked:

local MOUSE_ICON = "rbxasset://textures/GunCursor.png" -- Changes the mouse to the GunCursor Icon.
local RELOADING_ICON = "rbxasset://textures/GunWaitCursor.png" -- Changes the mouse icon to the Gun Wait Curso Icon.

local Player = game.Players.LocalPlayer

local Tool = script.Parent
local cooldown = false
local UserInputService = game:GetService("UserInputService")
local RemoteEvent = script.Parent:WaitForChild("RemoteEvent")

Tool.Equipped:Connect(function()
	UserInputService.MouseIcon = MOUSE_ICON
end)

Tool.Unequipped:Connect(function()
	UserInputService.MouseIcon = "rbxassetid://1"
end)

Tool.Activated:Connect(function()
	if not cooldown then 
		cooldown = true

		RemoteEvent:FireServer(Player:GetMouse().Hit)

		UserInputService.MouseIcon = RELOADING_ICON

		task.wait(5)

		UserInputService.MouseIcon = MOUSE_ICON

		cooldown = false
	end
end)

This is the script that creates the rocket and fire’s it off

local tool = script.Parent
local handle = tool.Handle
local remoteEvent = tool:WaitForChild("RemoteEvent")

local rocketSpeed = 200

remoteEvent.OnServerEvent:Connect(function(player, pos)
	print(pos)
	local rocket = Instance.new("Part")
	rocket.Size = Vector3.new(4, 1, 1)
	rocket.BrickColor = player.TeamColor
	rocket.CFrame = CFrame.new((handle.CFrame * CFrame.new(5, 0, 0)).Position, pos)
	rocket.Velocity = rocket.CFrame.LookVector * rocketSpeed
	rocket.Parent = workspace.Terrain
	
	local vectorForce = Instance.new("VectorForce")
	vectorForce.Enabled = true
	vectorForce.Parent = rocket
	vectorForce.Name = "Anti-Gravity"
	vectorForce.Force = Vector3.new(0, rocket:GetMass() * workspace.Gravity, 0)
	
	rocket.Touched:Connect(function(hit)
		if not hit:IsDescendantOf(player.Character) then
			local explosion = Instance.new("Explosion")
			explosion.Parent = workspace.Terrain
			explosion.Position = rocket.Position
			rocket:Destroy()
		end
	end)
end)
5 Likes

Mouse.Hit returns a CFrame, and you need two Vector3’s for the CFrame constructor, so change RemoteEvent:FireServer(Player:GetMouse().Hit) to RemoteEvent:FireServer(Player:GetMouse().Hit.Position) in the local script.

2 Likes

That ended up fixing it… But the vector force that is supposed to act as anti-gravity is really weird… And the explosion is also really weird…

2 Likes

yo bro, easy peasy fix:

local remote = script.Parent.RemoteEvent
local tool = script.Parent
local rocketSpeed = 600

remote.OnServerEvent:Connect(function(plr, pos)
local rocket = game.ReplicatedStorage.Rocket
local copy = rocket:Clone()
copy.Parent = workspace
copy.CFrame = CFrame.new((tool.Start.CFrame).Position, pos)
copy.Velocity = copy.CFrame.LookVector * rocketSpeed

local downForce = -copy:GetMass() * workspace.Gravity
local force = -downForce
local bodyForce = Instance.new("BodyForce")
bodyForce.Parent = copy
bodyForce.Force = Vector3.new(0, force, 0)

copy.Touched:Connect(function(hit)
	if not hit:IsDescendantOf(plr.Character) then
		local explosion = Instance.new("Explosion")
		explosion.Parent = workspace.Terrain
		explosion.Position = copy.Position
		copy:Destroy()
	end
end)

end)
Ii made a rocket mesh and put in repsotrage, if u want the aesthetics just do the same, or else modify the thing until ur happy

2 Likes

Hey uh, for one half of the code you sent me is unformatted and also this doesn’t really help me even though you gave me a script, because I don’t know at all what you changed except for the rocket mesh to fix it.

1 Like

I did what u asked, the thing works and it has now 0 gravity

1 Like

Yes, I know, but instead of just doing what I asked it would be better if you’ve given me an explanation of what you would’ve done to change it and then given me the script explaining what you changed and how that made it work, because to me you just gave me a script (haven’t tested it) and I don’t even know what you’ve changed to improve it…

I see a lot of people do this on the developer forum, and I can’t improve my scripting skills if all I am given is a script and no written explanation of what I can improve to fix the issue at hand.

And I know we don’t script the exact same way, but it would also be helpful if you kept up with the same variables and didn’t change anything major such as that because now I have to make tweaks for that…

1 Like

Sorry man, but i have no access to ur game so i made my own rocket launcher rq. But imma explain the script as best as i can.

-- Initialization
local remote = script.Parent.RemoteEvent -- Reference to a RemoteEvent in the parent of the script
local tool = script.Parent -- Reference to the parent of the script (presumably a tool)
local rocketSpeed = 200 -- Speed of the rocket

-- Event Handling
remote.OnServerEvent:Connect(function(plr, pos)
    -- Rocket Creation and Launch
    local rocket = game.ReplicatedStorage.Rocket -- Reference to the rocket model in ReplicatedStorage
    local copy = rocket:Clone() -- Clone the rocket
    copy.Parent = workspace -- Set the rocket as a child of the workspace
    copy.CFrame = CFrame.new(tool.Start.Position, pos) -- Position the rocket at the tool's "Start" position
    copy.Velocity = copy.CFrame.LookVector * rocketSpeed -- Set the velocity of the rocket

    -- Gravity Simulation
    local downForce = -copy:GetMass() * workspace.Gravity -- Calculate gravitational force
    local force = -downForce
    local bodyForce = Instance.new("BodyForce") -- Create a BodyForce to simulate gravity
    bodyForce.Parent = copy
    bodyForce.Force = Vector3.new(0, force, 0) -- Apply the force in the negative Y direction

    -- Rocket Collision Handling
    copy.Touched:Connect(function(hit)
        if not hit:IsDescendantOf(plr.Character) then
            -- Create an explosion at the rocket's position
            local explosion = Instance.new("Explosion")
            explosion.Parent = workspace.Terrain
            explosion.Position = copy.Position
            explosion.BlastPressure = 100 -- Adjust this value for a stronger force
            copy:Destroy() -- Destroy the rocket after the explosion
        end
    end)
end)


if any further questions lmk

1 Like

I know understand how it works and everything, but one issue with it is that sometimes it bounces off of a part when a collision is made, and the explosion “flies away” similar to how it did in the video I showed in the post.

(The video with the old script, just showing how the explosion kind of “flies away” with the script you’ve provided me with)

So the script works but the explosion is kind whack? is that what u mean?

1 Like

yes

So if u can describe me whats going wrong i maybe can help you, tell me whats not going as to plan

and then I provided the video up top

Well, it works for me. U shouldve have things in the part called “Snap” when the rocket collides then it explodes and it unanchors and just blasts yk? and i put blast pressure highter btw i set it to 500k.

and this is snap:
image

wanna know what snap is?
here: Snap | Documentation - Roblox Creator Hub

Here is a vid of me using the same rocketlauncher nothing modified only the blast pressure:
https://gyazo.com/5c39283fd74e3af8eef7cfcc05d178dd

found out that its deprecated… i took a model from the toolbox (i searched up “destroyable building”

so found out that if it contains weld or weld constraint that it can work too!

Also found out where that weird glitch comes from u were talking about, so if u hit urself it bounces of from u so u have to be aimbing forward or use:

else
			plr.Character:WaitForChild("Humanoid").Health = 0
			local explosion = Instance.new("Explosion")
			explosion.Parent = workspace.Terrain
			explosion.Position = copy.Position
			explosion.BlastPressure = 2000 -- Adjust this value for a stronger force
			copy:Destroy()

that kills the player and destroys the rocket
line 25


yeah so update:

i made new changes:

local remote = script.Parent.RemoteEvent
local tool = script.Parent
local rocketSpeed = 200

remote.OnServerEvent:Connect(function(plr, pos)
	local rocket = game.ReplicatedStorage.Rocket
	local copy = rocket:Clone()
	copy.Parent = workspace
	copy.CFrame = CFrame.new(tool.Start.Position, pos)
	copy.Velocity = copy.CFrame.LookVector * rocketSpeed

	local downForce = -copy:GetMass() * workspace.Gravity
	local force = -downForce
	local bodyForce = Instance.new("BodyForce")
	bodyForce.Parent = copy
	bodyForce.Force = Vector3.new(0, force, 0)
	
	wait(0.023)

	copy.Touched:Connect(function(hit)
		local explosion = Instance.new("Explosion")
		explosion.Parent = workspace.Terrain
		explosion.Position = copy.Position
		explosion.BlastPressure = 500000 --Change for stronger force yk

		if not hit:IsDescendantOf(plr.Character) then
			copy:Destroy()
		else
			plr.Character:WaitForChild("Humanoid").Health = 0
	
		end
	end)
end)

added a wait and added better functionality so it doesnt explode immediatly