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