Effective way to deal damage with projectiles without using the touched event>?

hello! im looking for a way to add damage to my projectiles without using touched. I know i can use raycasting but im unsure how to go about doing that.

I originalled planned to use runservice to constantly raycast, but i realize the loop would continue to run even after the projectile is destroyed, which would cause the loop to error.

So, is there a good way to deal damage with projectiles without using touched?

thank you for your time

2 Likes

i dont think its possible, there hasnt been a reply for around a month so im quite sure it isnt

Are you trying to make it so that when the object hits the player, it deals damage? If you do not care about the timing of the damage, then I suggest just using raycasting and if any part of that player model is there, deal the damage.

1 Like

You mentioned a projectile. So I am going to assume that this is for some kind of player controlled weapon.

The best way to do this is do a raycast in the direction of the player’s look vector or the click location of their mouse. If any part that is hit is a model that has a Humanoid child, then deal the damage and weld the projectile on the target. That’s how I handle bullets in my game.

2 Likes

Fastcast could be helpful. It is far more reliable than touched.

1 Like

You can disconnect the runservice loop after the projectile has been destroyed

local connection = nil
connection = RunService.Heartbeat:Connect(function(deltaTime)
      -- do your raycasting here
end)

Projectile.Destroying:Connect(function()
     If connection ~= nil and connection.Connected then
        connection:Disconnect()
     end 
end)

Try Overlap API like workspace:GetPartsInPart(projectile, param)
more efficient if u set blacklist/while list properly
works like GetTouchingParts()