local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
spawn(function()
local movementModule = require(script.Movement)
end)
local turrentsFolder = workspace.Turrents:GetChildren()
local bulletProperties = {
speed = 1150,
distanceToShootAt = 180,
damagePerHit = 24,
}
local function createBullet(bullet, startPos, velocity, parent)
local newBullet = bullet:Clone()
newBullet.Position = startPos
newBullet.Parent = parent
newBullet.Velocity = velocity
newBullet.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
local character = player.Character
character:FindFirstChildWhichIsA("Humanoid"):TakeDamage(bulletProperties.damagePerHit)
end
end)
end
local function bullet()
for _, children in pairs(workspace:GetChildren()) do
local hrp = children:FindFirstChild("HumanoidRootPart")
local humanoid = children:FindFirstChildWhichIsA("Humanoid")
for _, turrent in ipairs(turrentsFolder) do
if hrp and humanoid and (turrent.Gun.Position - hrp.Position).Magnitude <= bulletProperties.distanceToShootAt and humanoid.Health > 10 then
local ray = Ray.new(turrent.Gun.Position, (hrp.Position - turrent.Gun.Position).Unit * bulletProperties.distanceToShootAt)
local hit = workspace:FindPartsOnRayWithIgnoreList(ray, {turrent})
if hit == hrp then
createBullet(ServerStorage.Bullet, turrent.Gun.Position, turrent.Gun.CFrame.LookVector * bulletProperties.speed, workspace.Bullets)
else
warn("Part found in way")
end
end
end
end
end
while wait(1) do
bullet()
end
I’m all ears.