Bone breakage script is heavily delayed (about 3 seconds)

My script that is supposed to set the LimitsEnabled property to false on A BallSocketConstraint is pretty delayed. Now, the bone-breaking sound portion of the script works just fine however when the script actually does checks on the body part name and makes LimitsEnabled false, it is already past the sound, making it badly delayed.

Here is my code. (FOCUS ON LINE 13-14)

local soundTable =  script.Sounds:GetChildren() -- yooo automated

script.Parent.Touched:Connect(function(hit)
	if script.Parent.Velocity.Magnitude >= 120 then
		if not hit:IsDescendantOf(script.Parent.Parent) and hit.Transparency <1 and hit.Locked == false then
			local randomSound = soundTable[math.random(1, #soundTable)]
			local clonedSound = randomSound:Clone()
			clonedSound.Parent = script.Parent
			clonedSound:Play()
			wait(3)
			clonedSound:Destroy()
			
			if script.Parent.Name == "Left Leg" then
				script.Parent.Parent.Torso.LLRagdollJoint.LimitsEnabled = false
			end
		end
	end
end)

Any sort of help would be appreciated. Thanks!

You have wait(3) before checking the leg hence the delay. Move the wait(3) and clonedSound:Destroy() to after checking for the leg. Also use task.wait(3) instead.

1 Like

Are you using a part for the touched event, because if you do and without a debounce implemented into your script, the same event would fire like 20/30 times within a second. Maybe that can be the issue why it has a huge delay?

1 Like

Thank you so much for the solution!

I get where you’re coming from however I don’t experience that problem.