How can i script this security weapon

I have this here laser beam and cannon.
How can I make it so every time the player walks into the laser beam, the cannon will fire a homing projectile at the player?

You could do a .Touched event connected to a script that spawns a homing proj. with Align Position

I suggest not asking for entire scripts and rather asking for help on single bits of programming that you’re having issues with, as asking for whole systems breaks the rules of Scripting Support.

However you could use many things for this, try looking through Devforum and google for anything related to your “Homing projectile” issue. I’m sure there’s plenty information on it there.

I’m not going to write your script for you, but what I did when I made something like this (it is a gun sentry) is that I ran the players list on the server (Players:GetChildren()) and track the closest player who is not on the same team as the sentry. Once they are within a certain range, I started using Raycast to check visibility. If I hit the player, then the gun sentry would fire at the player. It wasn’t homing, but it keeps people on their toes.

2 Likes

.Touched event on the laser beam the easiest thing (even if not pretty than you can do) is Anchor the player model, then sent the projectile thro :Lerp() or game:GetService("TweenService") into the player’s character root and when it reaches there just kill them and :Destroy() the projectile (maybe a particle emitter or something for effect)

Break down of objectives:

  1. The turret aims at the closest player and shoots when the closest player is in range
  2. The bullet hits the player and makes a damage

What do we need to do:

  1. Detect the player
  2. Make the turret aim at the player
  3. Make the turret shoot
  4. Make the bullet damage the player

Task is broken down. Ask these questions individually