Make sure you're using instant pudding. If you used pudding that needs to be cooked, it won't set properly. It also helps to let the pudding thicken up a little before spreading it over the peanut butter mixture so that each layer remains distinct.