How do I make a ray visible?
I’m unsure of as to how to make a ray visible as I’m pretty new to raycasting, help would be appreciated.
My code:
local gun = script.Parent.Parent
local localPlayer = game.Players.LocalPlayer
local mouse = localPlayer:GetMouse()
local camera = workspace.CurrentCamera
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("DamageEvent")
gun.Activated:Connect(function(shoot)
local n = 10000
local rayOrigin = gun.Handle.Position
local rayDirection = mouse.Hit.Position
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {gun.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, (rayDirection - rayOrigin) * n, raycastParams)
if raycastResult.Instance.Parent:FindFirstChildOfClass("Humanoid") then
remoteEvent:FireServer(raycastResult.Instance.Parent:FindFirstChildOfClass("Humanoid"))
print("Detected something:", raycastResult.Instance:GetFullName())
print("Material Hit:", raycastResult.Material.Name)
else
print(raycastResult)
end
end)