Is there a reason you’re putting an event inside the loop? The event will fire even if you only set the callback once. That’s the point of an event. People have complained about that event being inaccurate though, so you could always try to use this inside of RenderStepped then disconnect RenderStepped when you want to disable it.
this is worst way, how you can do it, because you are creating the event every loop run, you must create empty local spike and than spawn this function
while Spike==nil
end
Spike.Touched:Connect(...................)
Looks like you’re doing it on the client. I’ve never seen what happens when you set the event callback in a while loop before really quickly but I could guess it probably isn’t the best thing ever. Try using BindToRenderStep and something like this module by EgoMoose that allows for rotated region3s to detect when something is in an area. As long as you don’t stress it out too much then you shouldn’t lag too much. If you’re messing with timings then make sure to use the delta time so it isn’t based on frame rate.
In simple, parts with complex geometries can cause the lag you mentioned when working with Touched events. Consider using magnitude checks or FindPartsInRegion3 as alternative solutions.
If possible, I recommend changing the part’s CollisionFidelity from Default to Box too.