Is there a way to get attachment beam to be moved with script and boolvalue?

I have a issue with lightsaber blade beam It suppose to move the beam attachment up when “Burn” is enabled but if it not enabled it go down to original position. (It suppose not use touched)
Here a code

local tweenService = game:GetService("TweenService")
local Users=game:GetService("Players")
local User=script.Parent.Parent.Parent
local Tool=script.Parent
local BLADE = Tool:WaitForChild("toolModel"):WaitForChild("B")
local Enabler = BLADE:WaitForChild("Burn")
local beam = BLADE:WaitForChild("beamattachment")
local tweeningInformation = TweenInfo.new(
0.25,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut,
0,
false,
0.5
)
local up = {CFrame = CFrame.new(0, 2.75, 0)};
local down = {CFrame = CFrame.new(0, -2.45, 0)}

local Tween1 = tweenService:Create(beam,tweeningInformation,up)
local Tween2 = tweenService:Create(beam,tweeningInformation,down)
local function bladeup()
if(Enabler.Value)then
		Tween1:Play()	
end
end
local function bladedown()
if(Enabler.Value)then
		Tween2:Play()
end
end

BLADE.Touched:Connect(bladeup)
BLADE.TouchEnded:Connect(bladedown)

Here you can see what the issue in action.

Is there way to fix this issue?

For this type of task, you should use GetPropertyChangedSignal to detect whether or not the Value property of Burn is being changed.

Enabler:GetPropertyChangedSignal("Value"):Connect(function()
  if Enabler.Value then
    Tween1:Play()
  else
    Tween2:Play()
  end
end)
1 Like

Alright I’ll try that one to see if it worked or not.

It worked! but…

Do you have 2 attachments for the dual sided light saber?

Yes but same name.

Are you moving both when you tween it? If not, that makes sense as to only one side goes.

Here you go!

function tweenBeams(arr)
  --I'm not sure what's in the model so I'll look for anything that contains "beamattachment"
  for _, blade in pairs(Tool.toolModel:GetChildren()) do
    if blade:FindFirstChild("beamattachment") then
      local beam = blade.beamattachment
      local Tween = tweenService:Create(beam,tweeningInformation,arr)
      Tween:Play()
    end
  end
end

Enabler:GetPropertyChangedSignal("Value"):Connect(function()
  if Enabler.Value then
    tweenBeams(up)
  else
    tweenBeams(down)
  end
end)


It worked! thank you @JackOfAllTrades101!

1 Like

No problem. Happy to help! :smile:

1 Like