How would I make a NPC hold a rocket launcher, and shoot it at the nearest humanoid?

The title pretty much says it all, I don’t know where to start. If there’s a tutorial somewhere, it would be awesome if you could link it.

1 Like

You could start with putting a classic Rocket Launcher tool inside the NPC and configure it to work there, and everything should do the rest.

Well, giving the NPC the tool should be simple enough as you can just clone the Rocket Launcher, then parent it to the NPC’s Model inside the workspace and it’ll automatically be held

For shooting it, you’d have to create a local function which would check all the Children inside the workspace if it has a Humanoid object or not using a loop of some sort frequently checking what’s the closest target

After it finds a valid target, it’ll return back the value to be used for later when we want to obtain it again:

local MaxDistance = 2500
local Tool = script.Parent
local NPC = Tool.Parent 
local RunService = game:GetService("RunService")

local function ChooseTarget(EnemyRoot)
    local ClosestTarget = nil

    for _, Target in pairs(workspace:GetChildren()) do
        if Target:FindFirstChild("Humanoid") and Target:FindFirstChild("HumanoidRootPart") then
            if ClosestTarget = nil and (Target.HumanoidRootPart.Position - EnemyRoot.Position).Magnitude < 2500 then
                ClosestTarget = Target

                return ClosestTarget
            end
        end
    end

end

while true do
    local Target = ChooseTarget(NPC.HumanoidRootPart)

    if Target then
        --Do your rocket launcher stuff here
    end
    RunService.Heartbeat:Wait()
end
6 Likes

Wait I have a question, could I use this tutorial that shows how to make a turret that automatically shoots, and just add it onto the NPC? (tutorial: Advanced Roblox Scripting Tutorial #24 - Raycasting (Beginner to Pro 2019) - YouTube )

Yeah you can, just be sure to orient the NPC’s HumanoidRootPart to where the Target currently is in order to fire the projectile properly in relevance to where it’s looking

So I need to make the humanoid root part of where the turret shoots point toward the object it is trying to shoot at? Idk how to do that, a YT tutorial would be nice

If you’re wanting to make a turret, you don’t need to reference a HumanoidRootPart

Just reference where turret’s barrel from where it’s gonna shoot and that should do it