How can I make projectile systems that detect hits way better

While I’m pretty decent in coding, I still sometimes have trouble on my projectiles. I didn’t want to use instant projectiles like bullets, I wanted to try making a projectiles like the classic doomspires slingshot. I tried making a hit detection for it but I just barely detects a hit when it’s supposed to.

I’m not so sure how to make small projectiles detect hits better. Might just be how small the projectile is that it phases through the characters. Below is my code for the projectile ability, I just want to know what could be wrong and how I can improve the code. feedback will be greatly appreciated!

		
		repeat
			local parts = workspace:GetPartsInPart(newPaintball)
				local RaycastResult = workspace:Raycast(newPaintball.Position, finalDirection * 4, Params)
				for i, hit in pairs(parts) do
					if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= character or RaycastResult then
						local isKiller = false
						
						if game.Players:GetPlayerFromCharacter(hit.Parent) then
							if game.Players:GetPlayerFromCharacter(hit.Parent).Team == game.Teams.Killers then
								isKiller = true
							end
						end
						
						if hit.Parent:IsDescendantOf(workspace.Killers) then
							isKiller = true
						end
						
						if isKiller and not table.find(HitTable,hit.Parent) then
							table.insert(HitTable, hit.Parent)
							print(hit.Parent.Name)
							if newPaintball.Name == "Paintball" then
								
								DamageDealer.DealKillerDamage(hit.Parent, CharacterStats.BillyBloxxer.PBDamage, nil, nil, nil)
								
								if game.Players:GetPlayerFromCharacter(hit.Parent) then
									VfxRemote:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent),{
										["EffectName"] = "BillyPaintBall",
									})
								end
								
								print("HIT")
							elseif newPaintball.Name == "Pebble" then
								DamageDealer.DealKillerDamage(hit.Parent, CharacterStats.BillyBloxxer.PBPebbleDamage, CharacterStats.BillyBloxxer.PBPebbleStunDuration, nil, nil)
							end
							newPaintball:Destroy()
						end
						task.wait()
					else
						print("Projectile still going.")
						task.wait()
					end
				end
				task.wait()
		until t - tick() >= 5

Recently, I’ve made a similar project type of system. The concept of how it works may be able to help you out here:

1st, determine where the projectile will fire towards(I prefer mouse hit, because then we can fire towards something, then calculate bullet drop as its moving)

2nd, use a temporary table, or store information into a "bullet’ variable to hold info on the bullets current velocity, bullet instance, position, and events such as “hit” and “disconnect” for cleanup.

3rd, using the bullet table, we can reference everything that is happening to it by passing it as a parameter into another function that will update the position, velocity, and decay of the bullet speed

4th, the most important and probably relevant to the post is that the bullet will raycast however far foward the current velocity would put is, every time it is updated
You can do this by taking the current position and setting it as a temp var called “old pos” or whatever, and then calculating the newPos with the current velocity held within the table.
Now you can raycast along that “velocity” because you have the before and after position

5th, Now you can update the new velocity. You can calculate gravity and velocity by multiplying it by delta time, and that will give you a velocity that you are going to want to store into your table so the next frame/render can use it to determine the next position/velocity

My hand are kinda getting tired, but this is jyst of a simple yet very reliable beginner projectile system. You can incorporate alot of different things aswell if you use the inititial table to store bindables/tempEvents, allowing you to destroy the bullet or add different functions into it really easily. I’ve personally used this system to add a reflecting off objects bounce effect to projectiles

i kinda got lazy towards 5, but if you have any questions re: