Why wont jump weight work?

Im trying to do a script where it plays animations depending on your state, all of the work except jump, so heres what i tried

walkanim:Play()
jumpanim:Play()
runanim:Play()
idleanim:Play()

local jumping = false


function checkAnims()
	print(jumping)
	
	if hum.MoveDirection.Magnitude == 0 then -- Idle
		--print(distance)
		runanim:AdjustWeight(0.00001, .3)
		walkanim:AdjustWeight(0.00001, 0.5)
		idleanim:AdjustWeight(1, 0.3)
		jumpanim:AdjustWeight(0.00001, 0.1)
	elseif hum.MoveDirection.Magnitude > 0 and script.Parent.CoreMovement.Sprinting.Value == false then -- Walk
		--print("Walking")
		runanim:AdjustWeight(0.00001, .3)
		walkanim:AdjustWeight(1, 0.5)
		idleanim:AdjustWeight(0.00001, 0.3)
		jumpanim:AdjustWeight(0.00001, 0.1)
	elseif hum.MoveDirection.Magnitude > 0 and script.Parent.CoreMovement.Sprinting.Value == true then --Run
		--print("Running")
		runanim:AdjustWeight(1, 1)
		walkanim:AdjustWeight(0.00001, 0.2)
		idleanim:AdjustWeight(0.00001, 0.1)
		jumpanim:AdjustWeight(0.00001, 0.1)
	elseif jumping == true then
		print("Jumping")
		runanim:AdjustWeight(0.00001, 0.001)
		walkanim:AdjustWeight(0.00001, 0.001)
		idleanim:AdjustWeight(0.00001, 0.001)
		jumpanim:AdjustWeight(1, 1)
	end	
end

while true do
	checkAnims()

	local Params = RaycastParams.new()
	local origin = hrp.Position 
	local direction = Vector3.new(0, -5, 0)


	Params.FilterType = Enum.RaycastFilterType.Exclude 
	Params.FilterDescendantsInstances = {script.Parent}

	local raycastResult = workspace:Raycast(hrp.Position, direction, Params)
	if raycastResult then
		if raycastResult.Distance >= 3 then
			jumping = true
		else 
			jumping = false
		end
	end
	task.wait()
end

If theres any ohter line of code you need me to show you say below, but yea ive tried this and many others and it still doesnt work

Could you use Humanoid.StateChanged() ?

ie:

Humanoid.StateChanged:Connect(function(old, new)
    if new == Enum.HumanoidStateType.Jumping then
        jumping = true
    end
end)

The jump variable DOES change but the animation refuses to play

Does print("Jumping") ever print? At a glance, it looks like the code could never actually reach if jumping == true because the previous if-statements always take priority.

Think about it! The character is always either going to be still (idle) or moving. Therefore, the final elseif will never get a chance to activate. Try swapping the final elseif with the first idle if statement.

1 Like

This fixed it, thank you so much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.