Laser Traps with Beams

Beams are an effect that can be used to create lasers, force fields, and even waterfalls. This object draws a texture between two points with customizable properties like speed, width, and curve.

Trap Setup

In this tutorial, you'll create a laser trap that uses a beam and insert a script to set a player's health to 0 when the trap is touched.

Add Attachments

Attachments are where one object can connect to another. In this case, attachments will be used for the start and end points of the beam.

Model with two green attachments
  1. Attachments aren't normally visible. To view attachments, toggle on Constraint Details in the Model tab.

    alt

  2. Create an anchored part or model named LaserTrap. Then, add two attachments named StartAttachment and EndAttachment.

Move Attachments

New attachments are created in the center of the part. For the beam, the attachments will need to be moved into position.

  1. Select StartAttachment (1) and use the Move tool to position it at the edge of the laser trap.

  2. Move EndAttachment (2) further away to where the laser should stop.

    alt

Create the Beam

With the attachments in place, a beam can now be created.

  1. Under LaserTrap, add a Beam object named Laser.

    alt

  2. With Laser selected, find Attachment0 in the Properties window. Click the empty box to the right of the property and then, in the Explorer, click StartAttachment.

  3. Set Attachment1 to EndAttachment using the same process. The properties should appear as below.

    alt

  4. By default, a beam doesn't always face the camera. This may lead to situations where players are unable to see a beam from different angles.

    Left View
    Top View

    So the beam is visible at any position, go into the beam properties and enable FaceCamera.

Beam Properties

Beams use 2D images that can be customized with properties to affect the color, size, or curvature.

  1. Copy the asset ID of an image you uploaded, or copy an ID from the examples below.

    rbxassetid://6060542021

    rbxassetid://6060542158

    rbxassetid://6060542252

  2. In the beam's Texture property, paste the asset ID.

  3. Make the laser appear brighter by changing a few properties.

    1. Add a faint glow by changing the LightEmission property to 0.5.
    2. Change Transparency to 0 (fully opaque).
  4. Make the beam wider by setting both Width0 and Width1 to 4.

  5. The TextureSpeed property animates the texture over time. For a fast, flickering effect, set it to 3.

  6. Make the laser look a bit more dangerous by changing its Color property.

Trap Mechanic

The script for the trap will check if an invisible part is touches a player. The part is used since beams don't have collision detection by default.

  1. In LaserTrap, create a new part named CollisionBox that overlaps the beam.

  2. Anchor CollisionBox so it doesn't move.

    alt

  3. In the main model or part named LaserTrap, add a new script. Copy the code below and paste it into the new script.


    1local laserTrap = script.Parent
    2local collisionBox = laserTrap:FindFirstChild("CollisionBox")
    3
    4-- Hide the collision box
    5collisionBox.Transparency = 1
    6
    7local function onTouch(otherPart)
    8 local character = otherPart.Parent
    9 local humanoid = character:FindFirstChildWhichIsA("Humanoid")
    10
    11 if humanoid then
    12 humanoid.Health = 0
    13 end
    14end
    15
    16collisionBox.Touched:Connect(onTouch)
    17
  4. Test the trap by walking into the laser beam. If it's not working correctly, make sure the script is in the right place and the collision box is properly named.

With the beam complete, explore additional beam properties like CurveSize0 and CurveSize1, import your own textures, or even make a new object like a force field.