I am relatively new to coding and am still learning... I was wondering if you could help me troubleshoot this:
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Down = false
Mouse.Button1Down:connect(function()
Down = true
while Down == true do
local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new("Bright red")
beam.FormFactor = "Custom"
beam.Material = "Neon"
beam.Transparency = 0.5
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local distance = (script.Parent.Head.CFrame.p - Mouse.Hit.p)
beam.CFrame = CFrame.new(script.Parent.Head.CFrame.p, Mouse.Hit.p) * CFrame.new(0, 0, -distance / 2)
game:GetService("Debris"):AddItem(beam, 0.01)
wait(0.01)
end
end)
Mouse.Button1Up:connect(function()
Down = false
end)
I was trying to make it draw a line from the head to the mouse that way players and friends could see what they were doing. I plan on making a GUI that says the name of what you are aiming at and the distance.

2 comments
+1. Very minor suggestion/question: wouldn't listening to Heartbeat be superior (compared to RenderStepped)? I'm told that listening to RenderStepped prevents Roblox from rendering graphics (until RenderStepped is done). Further, according to a diagram I found, Heartbeat occurs right after Physics and so seems like the right time to do it. (Not a big difference either way, of course.)
It doesn't matter much in this case because the code is not very intensive. I chose RenderStepped because I want the part to render smoothly.