Script code is stacking? Multiple prints in Output

Hi guys,

I am using a very complicated system which I have been building a game around.

Basically the issue that I am having is stemming from this code:

humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			humanoid.Jump = true
			
			humanoid.StateChanged:Connect(function(old,new)
				if new == Enum.HumanoidStateType.Jumping then
					print("JumpCon changed noticed")
					while humanoid:GetState() == Enum.HumanoidStateType.Jumping do
						Controller.GravityUp = Vector3.new(0,1,0)
						print("jumpCon gravity forced")
						wait()
						if humanoid:GetState() == Enum.HumanoidStateType.Landed then
							humanoid.PlatformStand = true
							break
						end
					end
				elseif new == Enum.HumanoidStateType.Freefall then
					Controller.GravityUp = Vector3.new(0,1,0)
					wait()
				elseif new == Enum.HumanoidStateType.Landed then
					humanoid.PlatformStand = true
				end
			end)

As you can see this code is making the player jump and is ensuring that their gravity is normal until they land.

This issue that I am having is that the two print functions within this code are seemingly stacking every time the player jumps.

Here is a screenshot of my output:

(please try to ignore the other prints in the output, only looking at the two Prints from the code)

In the screenshot at the very top you can that the print functions are only printed once each.

Going down the screenshot, it basically adds two more prints every time the player jumps.

Would somebody be able to tell me why this happening and how I can stop this?

You never use the old variable for anything. Might wanna check:
if new == old then return end

1 Like