Advertisement
Froyo1002YT

Multi-hitting raycast for LUA

Apr 23rd, 2023
1,300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | Gaming | 0 0
  1. -- multi-hitting raycast for LUA. This is using the program ROBLOX.
  2. --Any questions involving it ask here
  3. https://devforum.roblox.com/t/a-multi-hitting-raycast/2308623/3
  4. -- This is property of me so deal with it kid
  5.  
  6.  
  7. -- code
  8. local module = {}
  9.  
  10. function module.Raycast(po1,po2,ignoreParts)
  11.     local ignoreTable = {table.unpack(ignoreParts)}
  12.    
  13.     local params = RaycastParams.new()
  14.    
  15.     params.FilterDescendantsInstances = {ignoreTable}
  16.     params.IgnoreWater = true
  17.     params.FilterType = Enum.RaycastFilterType.Blacklist
  18.    
  19.     local finished = false
  20.     local hitItems = {}
  21.    
  22.     repeat
  23.         local params = RaycastParams.new()
  24.  
  25.         params.FilterDescendantsInstances = {ignoreTable}
  26.         params.IgnoreWater = true
  27.         params.FilterType = Enum.RaycastFilterType.Blacklist
  28.        
  29.        
  30.         local raycast = workspace:Raycast(po1,po2 - po1,params)
  31.        
  32.         if raycast then
  33.             -- we made a raycast!
  34.             if raycast.Instance then
  35.                 -- we hit something.
  36.                 table.insert(hitItems,raycast.Instance)
  37.                 table.insert(ignoreTable,raycast.Instance)
  38.                 warn('Hit item '..raycast.Instance.Name)
  39.             else
  40.                 -- there was nothing there.
  41.                 finished = true
  42.                 warn('Nothing hit!')
  43.             end
  44.             task.wait()
  45.         else
  46.             warn('No raycast')
  47.             finished = true
  48.         end
  49.         task.wait()
  50.     until finished == true
  51.     task.wait()
  52.    
  53.     return hitItems
  54. end
  55.  
  56.  
  57. return module```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement