function laser()
local laser = Instance.new("Part",player.Character)
laser.Size = Vector3.new(1,1,1) --makes the laser
laser.BrickColor = BrickColor.Red()
laser.CanCollide = false
laser.Anchored = true
laser.TopSurface = "Smooth"
laser.BottomSurface = "Smooth"
local mesh = Instance.new("CylinderMesh",laser)--mesh
--do raycasting.
local start = player.Character.Torso.Position -- the starting position
local ray = Ray.new(start,(mouse.Hit.p-start).unit*300) -- ray
local part,pos = game.Workspace:FindPartOnRay(ray,player.Character)
local dis = (start-pos).magnitude--the distance between the mouse hit and the start
mesh.Scale = Vector3.new(1,dis,1) -- scaling
laser.CFrame = CFrame.new(start,pos)*CFrame.new(0,dis/2,0)--this is the issue
end
I could make this easily work without the cylinder mesh, but it looks cooler hen cylindrical.
whenever I call this function, it makes the parts on my head, here's a visual of what I mean
