Code review on my turrent handler

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.

This was a year ago dude, don’t bring dead stuff back like this

1 Like

It was my opinion. I’m not so advanced scripter and I’m still learning. Why is this “dead” stuff?

Or do you mean this post doesn’t need a reply since it’s posted a year ago?

1 Like

Yeah, it’s just been a long time. Nothing wrong with it, but the post has been forgotten about and if you respond directly, it gets pushed to the top. If you still wanted to give an opinion, in this case it is likely better to message. Now, this isn’t the case of things like bugs and issues. If there was an issue or bug that hasn’t been brought up in a year, it’s probably better to reply to that topic so all the info on that bug can remain in one place.

1 Like

Oh, okay. I’ll keep it in mind. Thanks!