Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

.Touched event creates a hell ton of lag?

Asked by 4 years ago
Edited 4 years ago
01c.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

0
can you type full code? jerryisgod29 176 — 4y
0
the problem isnt the code its just this, the function never got fired, even if the .Touched function is empty it keeps to lag, only if theres no touched it will not lag arsen0839 -8 — 4y
0
Maybe potato PC? FLIPPER4440 21 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

maybe because cooldown is only 0.05?

0
i tried setting it to 5 it still lagged and i just said in the description even if the touched event is empty it still lags arsen0839 -8 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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.

0
alright i edited it and its still lagging check the question arsen0839 -8 — 4y
Log in to vote
0
Answered by 4 years ago

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

1if 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

0
check my edits, the problem didnt disappear arsen0839 -8 — 4y

Answer this question