Help with a rocket script

Can someone help me please? I would like to make a rocket that finds a nearest person at a game and the rocket takes 50% of damage of the nearest person, but I’m having struggles with it. I already know the basics, but I would like to know what do I need to script first to make this rocket. I already have the rocket model too.

This is a great object, as it’s capable of setting a Target property for the Rocket to find

For finding the nearest person, you’ll have to get all the players calling GetPlayers() inside the Players service, & check for the nearest Player using some “Target” variable & return it, to prevent the script from checking any more Players if there’s already a valid “Target”

And hopefully once you have everything set up, you can call Fire() to shoot the rocket :thinking:

You could do something like this as a brief example:

--A script inside the Rocket Model, keep in mind you'll probably have to reference the PrimaryPart in order to make it work
local RocketPropulsion = script.Parent.BaseRocket.RocketPropulsion
local Target = nil --We haven't found a target yet, so for now we set this as "nil"
local MaxDistance = 200 --The max distance for how far the target can detect players

for _, Player in pairs(game.Players:GetPlayers()) do --Looping through all the players that are currently in the game
    local Character = Player.Character

    if (Character.HumanoidRootPart.Position - script.Parent.BaseRocket.Position).Magnitude < MaxDistance and not Target then --Checking for the nearest player
        Target = Character --Setting our target
        RocketPropulsion.Target = Character.HumanoidRootPart --Setting where we want our Rocket to fire
        RocketPropulsion:Fire() --This is where we want to send the rocket to the Character
    else
        return --We want to return if there's no current targets or a Target is already set up
    end
end
1 Like

Thank you so much!!! But, are there 2 scripts? Because I saw a :Fire() there, and I don’t really know about Remote Events.
Like when the rocket hits the nearest player the player gets hit by 50% of damage.

Surprisingly enough, this is a RocketPropulsion object & when you call Fire() for that specific object, this would let the Rocket move towards the Character when a Target has been found

You might be thinking of RemoteEvent’s FireServer() function, or a BindableEvent’s Fire() function

Not sure what you quite mean by that, could you elaborate a bit? I’m a tad confused

1 Like

Ohh, that’s right I never noticed that. So how I can configure it so the player receives 50% of damage by the rocket?

I mean something like this
humanoid.health = 50

Oh I see

Well I suppose you could just simply use a Touched event to detect when the Rocket hits a specific Player or not

local DB = false

script.Parent.BaseRocket.Touched:Connect(function(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)

    if not DB and Player then
        DB = true
        local Character = Hit.Parent
        Character.Humanoid:TakeDamage(50)
    end
end)

Of course if you’d want to do it your way, you can do Character.Humanoid.Health = 50 to exclude Forcefield objects

1 Like