Creating max range for Beam / Attachment

I have been looking on the forum for anything which may help my issue. My main focus is for the beam to go invisible (Visible = false) when it reaches a certain distance. So if the range is set to 10 and the Beam is longer than 10 studs it goes invisible.

Is this possible? I just need some help and support on this issue I am having.

2 Likes

Grab the .Magnitude of both the beam’s attachments’ positions. Something like this;

local MaxLength = 10
local ExampleBeam = [Beam]

function GrabLength(ExampleBeam)
 if ExampleBeam and typeof(ExampleBeam) == 'Instance' and ExampleBeam.ClassName == 'Beam' then
  return math.abs((ExampleBeam.Attachment0.WorldPosition - ExampleBeam.Attachment1.WorldPosition).Magnitude)
 end
end

function CheckBeam()
 local BeamLength = GrabLength(ExampleBeam)
 if BeamLength > MaxLength then
  ExampleBeam.Enabled = false
 elseif not ExampleBeam.Enabled then
  ExampleBeam.Enabled = true
 end
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.