Advertisement
Guest User

fireScript

a guest
Jun 6th, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | Help | 0 0
  1. --[[
  2. BORING BORING GERMAN BORING
  3. What is this file? -This file is the actual shoot-em-up file. It spawns
  4. projectiles and registers damage.
  5. ]]
  6.  
  7.  
  8. -- imported variables
  9. local tool = script.Parent
  10.  
  11. local variablesFile = tool:WaitForChild("Properties")
  12. local damageValue = variablesFile:WaitForChild("damageValue")
  13.  
  14. print(damageValue, damageValue.Value)
  15.  
  16. local fireEvent = tool.fireEvent
  17. local muzzlePoint = tool.Muzzle.muzzlePoint
  18. local FastCast = require(game.ReplicatedStorage.Dependencies.FastCastRedux)
  19. local PartCache = require(game.ReplicatedStorage.Dependencies.PartCache)
  20.  
  21. local bulletsFolder = tool.Bullets
  22. local bulletTemplate = bulletsFolder.gen1Bullet
  23.  
  24. -- Getting data from "properties"
  25.  
  26. -- FastCast.VisualizeCasts = true
  27.  
  28. local caster = FastCast.new()
  29.  
  30. local castParams = RaycastParams.new()
  31. castParams.FilterType = Enum.RaycastFilterType.Exclude
  32. castParams.IgnoreWater = false
  33.  
  34. local bulletCache = PartCache.new(bulletTemplate, 100, bulletsFolder)
  35.  
  36. local castBehaviour = FastCast.newBehavior()
  37. castBehaviour.RaycastParams = castParams
  38. castBehaviour.Acceleration = Vector3.new(0, -workspace.Gravity, 0) -- gravity bullet drop
  39. castBehaviour.AutoIgnoreContainer = true
  40. castBehaviour.CosmeticBulletContainer = bulletsFolder
  41. castBehaviour.CosmeticBulletProvider = bulletCache
  42.  
  43. local function onEquipped()
  44. castParams.FilterDescendantsInstances = {tool.Parent, bulletsFolder}
  45. end
  46.  
  47. local function onLengthChanged(cast, lastPoint, direction, length, velocity, bullet)
  48. if bullet then
  49. local bulletLength = bullet.Size.Z/2
  50. local offset = CFrame.new(0, 0, -(length - bulletLength))
  51. bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
  52.  
  53. end
  54. end
  55.  
  56. local function onHit(cast, result, velocity, bullet)
  57. local hit = result.Instance
  58.  
  59. local damage = damageValue.Value
  60.  
  61. local character = hit:FindFirstAncestorWhichIsA("Model")
  62. local humanoid = character:FindFirstChild("Humanoid")
  63. print(script.Parent)
  64. print(script.Parent.Parent)
  65. print(damage)
  66. print(hit) --prints the part which the bullet hitted.
  67. if humanoid and hit.Name == "Head" then
  68. character.Humanoid:TakeDamage(damage)
  69. elseif humanoid and hit.Name == "LowerTorso" or humanoid and hit.Name == "UpperTorso" or humanoid and hit.Name == "HumanoidRootPart" then
  70. character.Humanoid:TakeDamage(damage)
  71. elseif humanoid then
  72. character.Humanoid:TakeDamage(damage)
  73. end
  74.  
  75. bulletCache:ReturnPart(bullet)
  76. end
  77.  
  78. local function fire(player, mousePosition)
  79. local origin = muzzlePoint.WorldPosition
  80. local direction = (mousePosition - origin).Unit
  81.  
  82. caster:Fire(origin, direction, 1000, castBehaviour) -- 3rd argument's velocity
  83. end
  84.  
  85. fireEvent.OnServerEvent:Connect(fire)
  86.  
  87. tool.Equipped:Connect(onEquipped)
  88.  
  89. caster.LengthChanged:Connect(onLengthChanged)
  90.  
  91. caster.RayHit:Connect(onHit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement