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

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 — 3y

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

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

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

Answer this question