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.
You said Nvm but I already wrote this so...
I want you to take away this script efficiency rather than just a tutorial. Most importantly that there is not much need for toggling a "Down" variable nor waiting a certain time.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() Mouse.Button1Down:connect(function() 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 conn = game:GetService('RunService').RenderStepped:connect(function() local p = Mouse.Hit.p local headp = script.Parent.Head.CFrame.p local distance = (headp-p).magnitude beam.Size = Vector3.new(0,distance,0) beam.CFrame = CFrame.new(headp:lerp(p,0.5), p)*CFrame.Angles(math.pi/2,0,0) end) Mouse.Button1Up:wait() conn:disconnect() beam:Destroy() end)
Nvm I got it working, thanks to pluginfactory.