Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

.Touched event creates a hell ton of lag?

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

3 comments

0

can you type full code?

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

0

Maybe potato PC?

3 answers

maybe because cooldown is only 0.05?

1 comment

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

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.

1 comment

0

alright i edited it and its still lagging check the question

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

1 comment

0

check my edits, the problem didnt disappear

This discussion is preserved as it was. New answers, comments, and votes are closed.