Fixing function

this function is weird asf, works like 20/100 chance idk

hum.StateChanged:Connect(function(_, newState)
	if newState == Enum.HumanoidStateType.Jumping and not soundDebounce then
		print("first")
		soundDebounce = true
		local jumpSoundName = jumpSounds[lastMaterial] or jumpSounds["Neutral"]
		local jumpSound = materials:FindFirstChild(jumpSoundName)
		print(lastMaterial)
		task.wait(0.005)
		if jumpSound then 
			makepartasound(jumpSound)
		else
			wait("what")
		end
		isJumping = true
		task.wait(0.1)
		soundDebounce = false

	elseif newState == Enum.HumanoidStateType.Landed and isJumping and not soundDebounce then
		soundDebounce = true
		local landSoundName = landingSounds[lastMaterial] or landingSounds["Neutral"]
		local landSound = materials:FindFirstChild(landSoundName)
		task.wait(0.005)
		print(lastMaterial)
		if landSound then 
			makepartasound(landSound)
		else
			wait("what")
		end
		isJumping = false
		task.wait(0.1)
		soundDebounce = false
	end
end)

i think it cause newstate, statechanged, but idk how to change it.

This post would be better suited for #help-and-feedback:scripting-support.

You’ll need to provide some additional info regarding it:

What is the function meant to do?
What does it currently do?
When it doesn’t work, does anything happen?
If you add print statements, are you sure it’s not just the soundDebounce messing things up?


Also,

wait("what")

Why. Just do wait() or wait(0)