Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Touched event causing lag?

So I made a projectile, however when the projectile passes through too many parts at once, it causes lag.

Something I tried to do was:

local debounce = false

part.Touched:Connect(function(hit)
	if debounce then return end
	debounce = true
	-- my code
	debounce = false
end)

However, this did not do the trick since the part's touched event was still firing everytime it passes through a part. Does anyone know any solutions to fix the lag issue?

5 comments

0

Ok I will try that

1

Try To loop through GetTouchingParts since that returns a table, it might lag less, Touched spawns a thread.

0

How often should I loop through GetTouchingParts?

0

Also I'd have to give all of my projectiles a TouchInterest right? (since all my projectiles are noncollide)

1 answer

I found a solution. I unioned my houses to make the touched event only act on one part (instead of like 20-50 parts). However I am quite sad that I wasn't able to keep my textures.

This discussion is preserved as it was. New answers, comments, and votes are closed.