Script(s) is running slow after first time running (Bc of ping?)

This script theoretically works, but it only runs right the first time, then it hesitates before running again.

When the part is touched the code basically turns the part invisible and non collidable while a clone falls. Additionally, there is a kill part (which in the WS is right on top of it) and turns that invisible and canCollide false too, plus is disables the script that kills the player). It doesn’t clone the kill part though.

CODE:

local part = script.Parent 
local debounce = false 

part.Touched:Connect(function(touched)
	if touched.Parent:FindFirstChild("Humanoid") and debounce == false then
		debounce = true 
		local copy = part:Clone()
		copy:FindFirstChild("FallScript"):Remove()
		part.Transparency = 1 
		part.CanCollide = false 
		copy.Parent = part.Parent
		copy.Anchored = false 
		part.Parent.KillPart2.Transparency=1
		script.Parent.Parent.KillPart2.KillScript.Disabled=true
		script.Parent.Parent.KillPart2.CanCollide=false
		wait(6) --SECONDS to wait for the part to come back or 'Respawn'
		debounce = false
		script.Parent.Parent.KillPart2.KillScript.Disabled=false
		script.Parent.Parent.KillPart2.CanCollide=true
		copy:Destroy() 
		part.Parent.KillPart2.Transparency=0
		part.Transparency = 0 
		part.CanCollide = true 
	end
end)

It works flawless the first time but the second time it waits a few seconds before it falls.

Is it possible this is a problem with my ping, I just tested and it ran as it was supposed to. Does ping affect stuff like this

1 Like

The debounce isn’t per-part. I would suggest basing the debounce off of the collideable property so that it functions per-part.

How can i modify my script do that though?

Also sorry this is so late

Replace this line with something like this
if touched.Parent:FindFirstChild("Humanoid") and part.CanCollide then

1 Like

Works good now, thanks! <3

That does work and it makes more sense too!

1 Like