[SOLVED] .Touched() event issue

I’m making a pretty simple destruction physics system where a ball (sort of like a cannon ball) is launched at a building using VectorVelocity. My system makes it so that every part the ball directly touches becomes unanchored. There is then a chance of collateral damage which damages surrounding parts. I made the parts that are directly touched by the projectile red and parts that have collateral damage cyan.

The issue with this script is the .Touched() event fires hundreds of times per second which I don’t think is very efficient. Is there any other way to go about doing this?

Before projectile launches (purple ball is projectile):

After projectile launches and bounces around inside of the building for a few seconds:

Is there a better way of going about this?

4 Likes

you could use a cooldown system – basic system shown here

local canDamage = true
local cooldown = 3

if canDamage == true then
   canDamage = false

   --[damage code here]

   task.wait(cooldown)
   canDamage = true
end

or, alternatively, only allow for one .Touched event to fire, ever:

local canDamage = true

if canDamage == true then
   canDamage = false

   --[damage code here]

end
4 Likes

I’m trying to replicate the physics system this game uses: Jenga Tower!❄️ - Roblox

I don’t think they use the methods you gave me since there doesn’t seem to be a cooldown or anything

2 Likes

i don’t know how exactly their destruction system works, but at the very least they do seem to use a small cooldown (under a second) so that the .Touched event doesn’t fire so often. they also seem to use checks to detect parts within a radius

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.