c.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil and Debounce == false then Debounce = true local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then Debounce = true onTouch(hit) else end wait(0.05) Debounce = false end 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
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