-- Defining Variables
local Player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
-- Misc Variables
local Range = 10
-- Script Requirements
local DoorsInRange = {}
local Terrain = workspace.Terrain
local Beam = Instance.new("Beam",Terrain)
local Attachment1 = Instance.new("Attachment",Terrain)
local Attachment2 = Instance.new("Attachment",Terrain)
local HumanoidRootPart = Player.Character.HumanoidRootPart
Beam.Width0 = 0.05
Beam.Width1 = 0.05
Beam.Attachment1 = Attachment1
Beam.Attachment0 = Attachment2
Player.Character.Humanoid.Died:Connect(function(Death)
	Beam:Destroy()
	Attachment1:Destroy()
	Attachment2:Destroy()
	warn("BeamS Restart")
end)
RunService.Heartbeat:Connect(function()
	for i,v in pairs(workspace:GetDescendants()) do
		if v.Name == "DetectionPart" then
			if #DoorsInRange <=1 then
				if table.find(DoorsInRange,v) == nil then
					table.insert(DoorsInRange,v)
				end
				if table.find(DoorsInRange,v) then
					local Mag = (v.Position - HumanoidRootPart.Position).Magnitude
					if (v.Position - HumanoidRootPart.Position).Magnitude <= 10 then
						Beam.Enabled = true
						Attachment1.CFrame = HumanoidRootPart.CFrame
						Attachment2.CFrame = v.CFrame
					elseif (v.Position - HumanoidRootPart.Position).Magnitude >= 10 then
						Beam.Enabled = false
					end
				end
			end
		end
	end
end)

1 comment

0

is this in a local or normal script?