Code:
-- CREATING THE BEAM:
function beam(NearestInteractable)
if not NearestInteractable:FindFirstChild("Beam") then
wait()
if NearestInteractable.InteractionSettings.RenderSettings.Beam.Value == false then return end
if not game.Players.LocalPlayer.Character.HumanoidRootPart:FindFirstChild("BeamAttachment1") then
A1 = Instance.new("Attachment", game.Players.LocalPlayer.Character.HumanoidRootPart)
A1.Name = "BeamAttachment1"
else
A1 = game.Players.LocalPlayer.Character.HumanoidRootPart:FindFirstChild("BeamAttachment1")
end
if not NearestInteractable:FindFirstChild("BeamAttachment2") then
A2 = Instance.new("Attachment", NearestInteractable)
A2.Name = "BeamAttachment2"
else
A2 = NearestInteractable:FindFirstChild("BeamAttachment2")
end
if not NearestInteractable:FindFirstChildOfClass("Beam") then
for _, v in pairs(interacts) do
if v.Parent:FindFirstChildOfClass("Beam") then
v.Parent:FindFirstChildOfClass("Beam").Name = "BeamDele"
v.Parent:FindFirstChildOfClass("Beam").Transparency = NumberSequence.new{
NumberSequenceKeypoint.new(0, v.Parent:FindFirstChildOfClass("Beam").Transparency),
NumberSequenceKeypoint.new(0.01, 0.2),
NumberSequenceKeypoint.new(0.02, 0.4),
NumberSequenceKeypoint.new(0.03, 0.6),
NumberSequenceKeypoint.new(0.04, 0.8),
NumberSequenceKeypoint.new(0.05, 1)
}
wait()
v.Parent:FindFirstChildOfClass("Beam"):Destroy()
end
end
wait(.1)
Beam = Instance.new("Beam", NearestInteractable)
Beam.Width0 = 0.1
Beam.Width1 = 0.1
Beam.Segments = 155
Beam.FaceCamera = true
Beam.Transparency = NumberSequence.new(1)
Beam.Texture = "http://www.roblox.com/asset/?id=5812000512"
Beam.TextureLength = 0.5
Beam.TextureSpeed = 0
Beam.Attachment0 = A1
Beam.Attachment1 = A2
end
local numbervalue = script:WaitForChild("Number1")
local newTween = ts:Create(numbervalue, TweenInfo.new(0.5), {Value = 0})
numbervalue:GetPropertyChangedSignal("Value"):Connect(function()
Beam.Transparency = NumberSequence.new(numbervalue.Value)
if NearestInteractable.InteractionSettings.RenderSettings.SecondGui.Value == false then fake.Enabled = false end
end)
newTween:Play()
newTween.Completed:Wait()
return
end
return
end
-- DELETING THE BEAM
for i,v in pairs(last_door:GetChildren()) do
if v:IsA("Beam") or v:IsA("SelectionBox") then
spawn(function()
v.Name = "BeamDele"
coroutine.wrap(function(toDelete)
pcall(function()
if toDelete:IsA("Beam") then
local numbervalue = script:WaitForChild("Number1")
numbervalue.Value = 0
spawn(function()
wait(.25)
toDelete:Destroy()
end)
toDelete.Transparency = NumberSequence.new{
NumberSequenceKeypoint.new(0.025, .1),
NumberSequenceKeypoint.new(0.05, .2),
NumberSequenceKeypoint.new(0.075, .3),
NumberSequenceKeypoint.new(0.1, .4),
NumberSequenceKeypoint.new(0.125, .5),
NumberSequenceKeypoint.new(0.15, .6),
NumberSequenceKeypoint.new(0.175, .7),
NumberSequenceKeypoint.new(0.2, .8),
NumberSequenceKeypoint.new(0.225, .9),
NumberSequenceKeypoint.new(0.25, 1)
}
else
local newTween = ts:Create(toDelete, TweenInfo.new(0.25, Enum.EasingStyle.Back), {Transparency = 1})
newTween:Play()
newTween.Completed:Wait()
if toDelete.Transparency >= 1 then
toDelete:Destroy()
else
local newTween = ts:Create(toDelete, TweenInfo.new(0.1, Enum.EasingStyle.Back), {Transparency = 1})
newTween:Play()
newTween.Completed:Wait()
toDelete:Destroy()
end
end
end)
end)(v)
end)
wait(.1)
end
end
So basically, I have a beam at the first part. Then when player leaves the vicinity of the first part and enters the vicinity of the second part, I try destroying the beam in the first part and adding a new one to the other. Problem is, this method won't work as long as there is a beam in the first part, and when the player nears the second part, the first beam won't go transparent and destroy until a second after the second beam is created, therefore not allowing the second beam to take its place.
