Is there a way to a beam have it's second attachment detect if something is in the way?

I have no idea about how that would work but
Is there a way where I can make the beam’s second attachment detect if something is in the way, for example a player, or a part? Literally anything? Because I want to make a realistic Moving Head System, just like in real life, the beams don’t go through walls, etc.

So… is there a way I can make the beams automatically adjust themselves down to where the part is, so not that the beams go through things, with a script?

Script demonstration would be appreciated.

Location of the beam:
image

I would suggest using

for i,v in pairs (game:GetService("Workspace").TaLights:GetChildren()) do

in the script, because I have multiple instances of these inside of the Folder.

Example: (sorry if the recording is laggy)

Thanks.

1 Like

You’d have to cast a ray in the direction of the beam and then move the attachment if an instance is found. A simple example of this would look something like such:

local part = -- Light here
local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
rayParams.FilterDescendantsInstances = {part}

local attachmentToMove = -- attachment here

part:GetPropertyChangedSignal("CFrame"):Connect(function()
   
   local ray = workspace:Raycast(part.Position, part.CFrame.LookVector * 50, rayParams)
   if ray then
      attachmentToMove.Position = ray.Position
   end
end)
1 Like

How would I use GetChildren() for this?
I have multiple instances of these, which have attachments inside of each individual instance?

You’d just loop the script for all of the parts and provide them with a getpropertychanged event

Alright, I will try that out.

I will get back to you if something is not working, or if it is, so I can let you know.

Sorry for the long wait, I had something important before this.
image
This is the problem?
image
And attachmentToMove is underlined
image

EDIT: Forget what I said, I forgot to define the light part on line 1.

The script sadly did not work, nor has any error been given out in Output.