Hello, im currently trying to create a LiDAR Gun similar to Scanner Sombre. I have the script in a tool and it does work, but it only creates one ball at the result position! It also places one ball per click and i would like to make it continuously scan when the player is pressing mousebutton1 if that makes sense.
ive tried adding this to the code but it will then put 20 parts at the same result position
maxRay = 20
for i = 1, maxRay do
…
my question is, how can i make multiple raycasts shoot from the same origin but place around eachother instead of together? I want the players to be able to scan the walls, roof, and floor to find the path out (all scannable parts will be under the same name for params purposes unless theres an easier way)
here is what i have so far;
local player = game:GetService(“Players”).LocalPlayer
local input = game:GetService(“UserInputService”)
local lidarGun = script.Parent
local handle = lidarGun.Handle
local folder = Instance.new(“Folder”, workspace)
folder.Name = “RayParts”
input.InputBegan:Connect(function(input, processed)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
print(“mouse clicked”)
local rayOrigin = handle.Position
local rayDirection = handle.CFrame.LookVector * 100 – 100 studs forward
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Include
raycastParams.FilterDescendantsInstances = {workspace.Wall}
local result = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if result then
print("Hit: ", result.Instance:GetFullName())
print("Position: ", result.Position)
print("Distance: ", (result.Position - rayOrigin).Magnitude)
local rayPart = Instance.new("Part")
rayPart.Shape = Enum.PartType.Ball
rayPart.Position = result.Position
rayPart.Size = Vector3.new(0.1, 0.1, 0.1)
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.BrickColor = BrickColor.new("Bright red")
rayPart.Material = Enum.Material.Neon
rayPart.Reflectance = .5
rayPart.Parent = folder
task.wait()
else
print("No hit detected.")
end
end
end)