I used one of alvinblox’s tutorials to make myself a gun. He showed how to raycast and all of that, the thing he didn’t show was how to visualize it. Sort of “see” the raycast. How would I do that? Here’s the code.
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(script.Parent.Handle.Position, (mousePos - script.Parent.Handle.Position)*300, raycastParams)
if raycastResult then
local distance = (script.Parent.Handle.Position - raycastResult.Position).Magnitude
local p = Instance.new("Part")
p.Anchored = true
p.CanCollide = false
p.Size = Vector3.new(0.1, 0.1, distance)
p.CFrame = CFrame.new(script.Parent.Handle.Position,script.Parent.Handle.Position*300)*CFrame.new(0, 0, -distance/2)
local hitPart = raycastResult.Instance
local model = hitPart:FindFirstAncestorOfClass("Model")
if model then
if model:FindFirstChild("Humanoid") then
model.Humanoid.Health -= 30
wait(.5)
p:Destroy()
end
end