local tool = script.Parent
local player = game.Players.LocalPlayer
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
local ray = Ray.new(tool.Handle.CFrame.p,(mouse.Hit.p - tool.Handle.CFrame.p).unit * 300) -- Why use p instead of Position?
local part, position= game.Workspace:FindPartOnRay(ray,player.Character,false,true) -- does this define both, the player that got hit and the position of that player?
local beam = Instance.new("Part",tool)
beam.Material = "SmoothPlastic"
beam.Transparency = 0.5
beam.Anchored = true
beam.CanCollide = false
beam.Locked = true
local distance = (tool.Handle.CFrame.p - position).magnitude -- Purpose of magnitude?
beam.Size = Vector3.new(0.3, 0.3, distance) -- Purpose of distance on the z-axis?
beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0,0,-distance/2) -- What does the -distance/2 on the z-axis do?
if part then
local hum = part.Parent:FindFirstChild("Humanoid")
if not hum then
local hum = part.Parent:FindFirstChild("Humanoid") -- is this line necessary?
end
if hum then
hum:TakeDamage(15)
end
end
game:GetService("Debris"):AddItem(beam,0.5)
end)
end)
I've put the questions next to the lines of code that i need help with.

1 comment
magnitude returns the length of a vector3 value