01 | c.Touched:Connect( function (hit) |
02 | if hit.Parent:FindFirstChild( "Humanoid" ) ~ = nil and Debounce = = false then |
03 | Debounce = true |
04 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
05 | if player then |
06 | Debounce = true |
07 | onTouch(hit) |
08 | else |
09 |
10 | end |
11 | wait( 0.05 ) |
12 | Debounce = false |
13 | end |
14 | end ) |
this lags the game for no reasons the onTouch(hit) function never even fires and it still lags even if i empty the inside of .touched event the hell can i do to remove the lag it drops fps to 30
maybe because cooldown is only 0.05?
If you are defining debounce inside of the function, try defining it outside of the function or checking other scripts in the game. Other than that, I'm unsure.
I think its because you're distributing this to every part or thing that it's touching instead of the human itself. maybe you should narrow it down to only the character by using
1 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
Otherwise, if you are finding every single part, it probably will lag a lot, and you should probably make a list for the items you want to activate when it touches